下面的代码是获取UIView,作为UIImage保存到Docs Dir。
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
UIImage保存成功,但是分辨率非常差。如下图,怎么提高图片的质量?和原来的图片一样最好。
可以在调用UIGraphicsBeginImageContext(view.bounds.size)时,将其第一个参数设置为高分辨率的值,例如:UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 2.0)。第三个参数是屏幕分辨率,可以将其设置为2.0或3.0来提高图片的质量。