iOS screenshot function

iOS screen capture function , you can customize the interface to capture any View
(I don't know if there are other methods, I am learning to draw recently, and I use the drawing method to capture the screen): The method is as follows

-(UIImage *)returnImageFromView:(UIView *)view{
    // 1.创建bitmap上下文
    UIGraphicsBeginImageContext(view.frame.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    // 2.将要保存的view的layer绘制到bitmap上下文中,想截取谁view就写谁
    [view.layer renderInContext:ctx];
    // 3.取出绘制好的图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    return newImage;
}
// 保存到相册
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);



- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error) {
        [MBProgressHUD showError:@"保存失败"];
    }else
    {
        [MBProgressHUD showSuccess:@"保存成功"];
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325528140&siteId=291194637