objective-c – 将程序截图以mac方式存储在应用程序窗口中

我必须添加对我的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]);

我应该在代码中改变什么,所以我只能收到我的应用程序的窗口?

解决方法

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

请检查并让我知道.这是捕获的当前活动窗口.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...