我必须为我的 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]);
我应该在代码中进行哪些更改,以便只获得我的应用程序窗口?