UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
_currentImage = [self getImageFromView:webView];
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(_currentImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
- (UIImage *)getImageFromView:(UIView *)view
{
UIImage *pngImg;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(viewSize.width, viewSize.height),YES,[UIScreen mainScreen].scale);
// 设置view成全部展开效果
[view setFrame: CGRectMake(0, 0, view.size.width, view.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
pngImg = UIGraphicsGetImageFromCurrentImageContext() ;
UIGraphicsEndImageContext();
return pngImg;
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *message = @"text";
if (!error) {
message = @"成功保存到相册";
}else
{
message = [error description];
}
}
注意:scale(缩放因子)大小影响截图内容清晰度,尽量写[UIScreen mainScreen].scale