IOS:关于iPhone/iPad全屏截图与区域截图的几种方法总结
2013-01-17 10:08
1011 查看
截取本区域(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);
全屏截图:
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) .
截图另存为指定名字:
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:[documentsDirectorystringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWriteerror:&error];
部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app
没有ipad真机截图发布app的可以用此方法做个透明按钮点,哈哈.
//播放截图声音
NSString* path = [[NSBundle mainBundle]
pathForResource:@”photoShutter” ofType:@”caf”];
//NSString *path = [[NSBundle
bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@”Tink”
ofType:@”aiff”];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL
fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
// we don’t dispose of the sound to keep the sound in the cache for
the next time
AudioServicesDisposeSystemSoundID(soundID);
可以用这顺带播放一下声音
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);
全屏截图:
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) .
截图另存为指定名字:
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:[documentsDirectorystringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWriteerror:&error];
部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app
没有ipad真机截图发布app的可以用此方法做个透明按钮点,哈哈.
//播放截图声音
NSString* path = [[NSBundle mainBundle]
pathForResource:@”photoShutter” ofType:@”caf”];
//NSString *path = [[NSBundle
bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@”Tink”
ofType:@”aiff”];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL
fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
// we don’t dispose of the sound to keep the sound in the cache for
the next time
AudioServicesDisposeSystemSoundID(soundID);
可以用这顺带播放一下声音
相关文章推荐
- 关于iPhone/iPad全屏截图与区域截图的几种方法总结
- 关于iPhone/iPad全屏截图与区域截图的几种方法总结
- 关于iPhone/iPad全屏截图与区域截图的几种方法总结
- 关于iPhone/iPad全屏截图与区域截图的几种方法总结
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图的几种方法
- iPhone/iPad全屏截图与区域截图
- iPhone开发下载网络数据的几种方法总结
- 关于iOS去除数组中重复数据的几种方法
- 关于iOS 数据请求ASIHttpRequest方法的总结
- 【已解决】Ipad 1代-随意下载应用软件(此方法,同样适用于IOS 5.1.1的Iphone手机)
- iphone/ipad关于size, frame and bounds总结和UIScroll view学习笔记
- [分享]xcode免证书真机调试iphone(ipad)程序的具体方法(总结贴))
- iOS里常见的几种信息编码、加密方法简单总结
- 关于ios访问HTTPS站点的几种方法
- iOS:关于iPhone连接Xcode时,RSA加密失败的一点总结