iPhoneiPad全屏截图与区域截图的几种方法

iPhoneiPad全屏截图与区域截图的几种方法,第1张

概述截取本区域(self.view): 1 2 3 4 5 UIGraphicsBeginImageContext (CGSizeMake (self.view.frame.size.width, self.view.frame.size.height ) );     [self.view.layer renderInContext :UIGraphicsGetCurrentContext ( )

截取本区域(self.vIEw):

1
2
3
4
5
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 );

全屏截图:

1
2
3
4
5
6
UIWindow *screenWindow = [ [UIApplication sharedApplication ] keyWindow ];
    UIGraphicsBeginImageContext (screenWindow.frame.size );
    [screenWindow.layer renderInContext :UIGraphicsGetCurrentContext ( ) ];
    UIImage *vIEwImage = UIGraphicsGetimageFromCurrentimageContext ( );
    UIGraphicsEndImageContext ( );
    UIImageWritetoSavedPhotosAlbum (vIEwImage,nil );

以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片

苹果最新开放的接口函数(全屏截图),已经有人试过了,不会reject:

1
2
3
4
5
CGImageRef UIGetScreenImage ( );
    CGImageRef img = UIGetScreenImage ( );
    UIImage * scImage = [UIImage imageWithCGImage :img ];
    UIImageWritetoSavedPhotosAlbum (scImage,nil );
It still works,but only on -device (not in simulator ) .

截图另存为指定名字:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 ];

部分代码来自:http://stackoverflow.com/questions/692464/emailing-full-screen-of-iphone-app

没有ipad真机截图发布app的可以用此方法做个透明按钮点,哈哈.
截取本区域(self.vIEw):

1
2
3
4
5
UIGraphicsBeginImageContext (CGSizeMake (self.vIEw.frame.size.wIDth,nil );

全屏截图:

1
2
3
4
5
6
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
    UIGraphicsBeginImageContext(screenWindow.frame.size);
    [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *vIEwImage = UIGraphicsGetimageFromCurrentimageContext();
    UIGraphicsEndImageContext();
    UIImageWritetoSavedPhotosAlbum(vIEwImage,nil,nil);

以上2种方法真机和模拟器都可以运行.在photo.app里可以看到照片

苹果最新开放的接口函数(全屏截图),but only on -device (not in simulator ) .

截图另存为指定名字:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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,YES );
NSString *documentsDirectory = [paths objectAtIndex : 0 ];

NSError *error = nil;
[screenshotPNG writetofile : [documentsDirectory stringByAppendingPathComponent : @ "screenshot.png" ] options :NSAtomicWrite error :&error ];
总结

以上是内存溢出为你收集整理的iPhone/iPad全屏截图与区域截图的几种方法全部内容,希望文章能够帮你解决iPhone/iPad全屏截图与区域截图的几种方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1089642.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存