概述
http://www.cocoachina.com/newbie/tutorial/2012/0905/4709.html
1. 截取本区域(self.view):
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
2. 全屏截图:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片
苹果最新开放的接口函数(全屏截图),已经有人试过了,不会reject:
CGImageRef UIGetScreenImage();
CGImageRef img = UIGetScreenImage();
UIImage* scImage=[UIImage imageWithCGImage:img];
UIImageWriteToSavedPhotosAlbum(scImage, nil, nil, nil);
It still works,but only on-device (not in simulator) .
3. 截图另存为指定名字:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *screenshotPNG = UIImagePNGRepresentation(screenshot);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError *error = nil;
[screenshotPNG writeToFile:[documentsDirectory stringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWrite error:&error];
最后
以上就是眼睛大猎豹为你收集整理的iPhone/iPad全屏截图与区域截图的几种方法的全部内容,希望文章能够帮你解决iPhone/iPad全屏截图与区域截图的几种方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复