ios 截屏功能(高清图)

2018-05-24  本文已影响10人  Debugs

可以通过以下代码实现截屏,然后保存到相册。

-(void)savePicture{
1.传入要截屏的view,并转换为UIImage
    UIImage * image = [self captureImageFromView:self.view];
2.写入相册(不要忘记加info中添加相册的写入权限!!!)
    ALAssetsLibrary * library = [ALAssetsLibrary new];
    NSData * data = UIImageJPEGRepresentation(image, 1.0);
    [library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:nil];
}
-(UIImage *)captureImageFromView:(UIView *)view
{
    CGRect screenRect = [view bounds];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);//原图
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:ctx];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    return image;
}
上一篇下一篇

猜你喜欢

热点阅读