mac 10.6.8 xcode 版本 3.2.6 桌面应用通过
截图代码
-
static void savePNGImage(CGImageRef imageRef, NSString *path)
-
{
-
-
-
NSURL *fileURL = [NSURL fileURLWithPath:path];
-
CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
-
-
CGImageDestinationAddImage(dr, imageRef, NULL);
-
CGImageDestinationFinalize(dr);
-
-
CFRelease(dr);
-
}
-
-
static void save()
-
{
-
CGDirectDisplayID displayID = CGMainDisplayID();
-
CGImageRef imageRef = CGDisplayCreateImage(displayID);
-
-
NSString *path = [@"~/Desktop/public.png" stringByExpandingTildeInPath];
-
NSLog(@"save file: %@", path);
-
savePNGImage(imageRef, path);
-
-
CFRelease(imageRef);
-
}
按钮点击 调用
-
-(IBAction) btnScreenShot:(id) sender{
-
printf("screen short start\n");
-
save();
-
}
关联事件后,触发后, 将在桌面保存 png 桌面截图
阅读(1765) | 评论(0) | 转发(0) |