iOS 截屏

截取屏幕并保存本地

1. 截图

- (UIImage*)createImageWithView:(UIView*)view{

   CGSize s = view.bounds.size;

    UIGraphicsBeginImageContextWithOptions(s, YES,[UIScreen mainScreen].scale);

    [viewdrawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimage;

}

2.保存到相册

- (void)saveImageToAlbum{

    UIImage* image = [selfcreateImageWithView:self.webView];

UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), (__bridgevoid*)self);

}

- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo

{

    if(!error){

       // NSLog(@"保存成功");

        [self.viewmakeToast:@"保存成功"];

    }else{

         [self.viewmakeToast:@"保存失败"];

         NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容