8

Mac OSでObjectiveCを使用して画面をキャプチャする方法を知っている人はいますか?具体的には、アクティブ/フォーカスされたアプリケーション画面をキャプチャしてから、指定したパスに画像を作成するにはどうすればよいですか。
どんな助けでも大歓迎です。

4

3 に答える 3

10

@ダニエル、「グラブの息子」全体を理解して実装する必要はありません。以下のコードが必要です。

次の関数はスクリーンショットを提供します

// This just invokes the API as you would if you wanted to grab a screen shot. The equivalent using the UI would be to
// enable all windows, turn off "Fit Image Tightly", and then select all windows in the list.
CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);

次のコードを使用して、NSImage に変換します。

NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:screenShot];
// Create an NSImage and add the bitmap rep to it...
NSImage *image = [[NSImage alloc] init];
[image addRepresentation:bitmapRep];
[bitmapRep release];
bitmapRep = nil;
于 2011-09-23T10:25:22.067 に答える
4
于 2009-11-06T14:30:25.793 に答える
1

AppleのOpenGLScreenSnapshotも確認できます

于 2010-09-03T06:11:24.127 に答える