Converting UIView to UIImage gives poor quality

那年仲夏 提交于 2019-12-10 17:55:11

问题


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

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?


回答1:


Use UIGraphicsBeginImageContextWithOptions instead of UIGraphicsBeginImageContext

UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);

Tell me its working or not :)




回答2:


Capture the image of Entire view using below code :-

 UIGraphicsBeginImageContext(view.frame.size); 


来源:https://stackoverflow.com/questions/18229251/converting-uiview-to-uiimage-gives-poor-quality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!