9

OSX アプリにスクリーンショットを撮る機能を追加する必要がありますが、Apple のデモでは画面全体の画像しか表示されず、アプリケーション ウィンドウの画像のみが表示されます。

私のコードは次のとおりです。

NSInteger displaysIndex = 0;
if(displays != nil)
{
    free(displays);
}


CGError             err = CGDisplayNoErr;
CGDisplayCount      dspCount = 0;

/* How many active displays do we have? */
err = CGGetActiveDisplayList(0, NULL, &dspCount);

/* If we are getting an error here then their won't be much to display. */
if(err != CGDisplayNoErr)
{
    return;
}
/* Allocate enough memory to hold all the display IDs we have. */
displays = calloc((size_t)dspCount, sizeof(CGDirectDisplayID));

// Get the list of active displays
err = CGGetActiveDisplayList(dspCount,
                             displays,
                             &dspCount);

/* Make a snapshot image of the current display. */
CGImageRef image = CGDisplayCreateImage(displays[displaysIndex]);

アプリのウィンドウのみを取得するには、コードで何を変更すればよいですか?

4

2 に答える 2

8

単純。

NSImage *captureImage  = [[NSImage alloc] initWithData:[self.view dataWithPDFInsideRect:[self.view bounds]]];

確認してお知らせください。これはキャプチャされた現在アクティブなウィンドウです。

于 2013-03-16T07:08:47.877 に答える
7

フレームと影を含むウィンドウのスクリーンショットを実際に撮るには、ウィンドウを取得し関数windowNumberに渡します。CGWindowListCreateImage

于 2013-03-17T03:30:22.850 に答える