美文网首页
ios 截屏功能(高清图)

ios 截屏功能(高清图)

作者: Debugs | 来源:发表于2018-05-24 10:40 被阅读10次

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

    -(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;
    }
    

    相关文章

      网友评论

          本文标题:ios 截屏功能(高清图)

          本文链接:https://www.haomeiwen.com/subject/lybjjftx.html