objective-c – 将程序截图以mac方式存储在应用程序窗口中
发布时间:2020-12-16 03:45:42 所属栏目:百科 来源:网络整理
导读:我必须添加对我的OSX应用程序截图的能力,但是Apple演示只会给我整个屏幕图像,我只想要我的应用程序窗口图像. 我的代码是: NSInteger displaysIndex = 0;if(displays != nil){ free(displays);}CGError err = CGDisplayNoErr;CGDisplayCount dspCount = 0;/*
我必须添加对我的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]]]; 请检查并让我知道.这是捕获的当前活动窗口. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |