将UIView转换为UIImage会产生较差的质量 [英] Converting UIView to UIImage gives poor quality
本文介绍了将UIView转换为UIImage会产生较差的质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码将UIView捕获为UIImage并将其保存在Docs Dir中.
I am using the following code to capture a UIView as a UIImage and save it in Docs Dir.
- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
UIImage已成功保存.但是,分辨率非常差.请参阅下图以供参考.如何确保按照原始图像保留分辨率?
The UIImage is successfully saved. However the resolution is very poor. See the image below for reference. How do I make sure the resolution is retained as per the original image?
推荐答案
使用 UIGraphicsBeginImageContextWithOptions 代替 UIGraphicsBeginImageContext
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
告诉我它是否有效:)
这篇关于将UIView转换为UIImage会产生较差的质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文