iOS截屏代码

简介: <p style="padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:10px; clear:both; height:auto; overflow:hidden; font-size:14px; font-family:Menlo; color:rgb(0,132,0)"> <span class="c

/**

 *截图功能

 */

-(void)screenShot{

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(640, 960), YES, 0);

    //设置截屏大小

    [[self.view layerrenderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    CGImageRef imageRef = viewImage.CGImage;

    CGRect rect = CGRectMake(00641SCREEN_HEIGHT + 300);//这里可以设置想要截图的区域

    CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);

    UIImage *sendImage = [[UIImage allocinitWithCGImage:imageRefRect];

 

   //以下为图片保存代码

   UIImageWriteToSavedPhotosAlbum(sendImage, nilnilnil);//保存图片到照片库

    NSData *imageViewData = UIImagePNGRepresentation(sendImage);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *pictureName= @"screenShow.png";

    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:pictureName];

    [imageViewData writeToFile:savedImagePath atomically:YES];//保存照片到沙盒目录

    CGImageRelease(imageRefRect);    


   //从手机本地加载图片

   UIImage *bgImage2 = [[UIImage alloc]initWithContentsOfFile:savedImagePath];

    

}

2UIScrollView截屏(一屏无法显示完整)

/** *截图 */- (void)screenShot{    UIImage* image = nil;    UIGraphicsBeginImageContext(m_scrollView.contentSize);    {        CGPoint savedContentOffset = m_scrollView.contentOffset;        CGRect savedFrame = m_scrollView.frame;        m_scrollView.contentOffset = CGPointZero;        m_scrollView.frame = CGRectMake(0, 0, m_scrollView.contentSize.width, m_scrollView.contentSize.height);        [m_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];        image = UIGraphicsGetImageFromCurrentImageContext();             m_scrollView.contentOffset = savedContentOffset;        m_scrollView.frame = savedFrame;    }    UIGraphicsEndImageContext();        if (image != nil) {        NSLog(@"截图成功!");    }}
目录
相关文章
|
6天前
|
移动开发 安全 数据安全/隐私保护
iOS 全局自动化代码混淆工具!支持 cocoapod 组件代码一并混淆
iOS 全局自动化代码混淆工具!支持 cocoapod 组件代码一并混淆
|
6天前
|
移动开发 前端开发 安全
最强大的 iOS 应用源码保护工具:Ipa Guard,保护你的商业机密代码
最强大的 iOS 应用源码保护工具:Ipa Guard,保护你的商业机密代码
|
6天前
|
移动开发 前端开发 数据安全/隐私保护
【工具】iOS代码混淆工具-iOS源码混淆
【工具】iOS代码混淆工具-iOS源码混淆
45 1
|
7月前
|
移动开发 前端开发 数据安全/隐私保护
iOS代码混淆-从入门到放弃
iOS代码混淆-从入门到放弃
93 0
|
6天前
|
缓存 开发工具 iOS开发
优化iOS中Objective-C代码调起支付流程的速度
优化iOS中Objective-C代码调起支付流程的速度
17 2
|
6天前
|
移动开发 安全 数据安全/隐私保护
iOS 代码混淆和加固技术详解
iOS 代码混淆和加固技术详解
|
6天前
|
移动开发 前端开发 数据安全/隐私保护
iOS 代码混淆 - 从入门到放弃
iOS 代码混淆 - 从入门到放弃
|
6天前
|
安全 算法 数据安全/隐私保护
iOS 代码加固与保护方法详解 - 提升 iOS 应用安全性的关键步骤
iOS 代码加固与保护方法详解 - 提升 iOS 应用安全性的关键步骤
|
6天前
|
安全 Java Android开发
iOS代码安全加固利器:深入探讨字符串和代码混淆器的作用
iOS代码安全加固利器:深入探讨字符串和代码混淆器的作用
38 0
|
6天前
|
移动开发 安全 前端开发
iOS代码混淆工具
iOS代码混淆工具
64 1