How to save UIView with subviews without losing quality?

时间:2015-09-14 15:34:17

标签: objective-c uiview uiimage

I am trying to save the view with its subview, but the saved image is little bit blurry (especially the label's text)

I tried all the solutions given in stackoverflow - no use.

Can anyone help me on the same?

I am using the below code

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0);        
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];        
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();        
    UIGraphicsEndImageContext();

enter image description here

And getting the blurred text, also the picture quality is low.

2 个答案:

答案 0 :(得分:0)

您可以尝试更高分辨率的图像。如果将高分辨率图像压缩到较低位置应该没问题,但是将低分辨率图像放大到较大尺寸通常会使图像内容模糊,因为它会拉伸所有内容。

答案 1 :(得分:0)

首选方法是[UIView snapshotViewAfterScreenUpdates:]。如果您打算应用其他效果,则应该只使用drawViewHierarchyInRect:afterScreenUpdates:

也就是说,根据您操作或保存图像的方式,有几种可能的原因。例如,以JPEG格式保存文本会导致模糊。无需小心旋转或缩放图像会使文本模糊。错误地绘制图像(例如,未能像素对齐)可能会使文本模糊。如果您正在执行多个步骤,则应简化问题,并在每个步骤验证质量。要在StackOverflow上进一步讨论,您需要提供有关如何操作和显示图像的详细信息,而不仅仅是如何生成图像。

文字极易受到文物的影响。如果你必须拍照(如果可能的话,你通常应该避免的事情),你应该尽可能少地操纵它。在绘制文本之前而不是之后操作文本总是更好。