0

ビューの画像を取得しようとしているので、NSImageView.

NSViewSbitmapImageRepForCachingDisplayInRect:方式を採用しています。
ただし、このメソッドは、ウィンドウの背景なしで、ビューの内容のみを返します。

画面に表示されているように、背景色などでビュー全体の画像を取得するにはどうすればよいですか?


現在のコード

- (NSImage *)imageOfView:(NSView *)view {
    NSBitmapImageRep* rep = [view bitmapImageRepForCachingDisplayInRect:view.bounds];
    [view cacheDisplayInRect:view.frame toBitmapImageRep:rep];

    return [[NSImage alloc] initWithCGImage:[rep CGImage] size:view.bounds.size];
}
4

1 に答える 1

1

プロジェクトからのこの声明

/* Get the index for the chosen display from the CGDirectDisplayID array. */
NSInteger displaysIndex = [menuItem tag];
/* Make a snapshot image of the current display. */
CGImageRef image = CGDisplayCreateImage(displays[displaysIndex]);
于 2013-03-21T09:14:11.367 に答える