我有一个 UIView
,我想将它的内容保存到图像中,我使用 UIGraphicsBeginImageContext
和 UIGraphicsGetImageFromCurrentImageContext()
成功做到了,但是问题是图像质量降低了。有没有办法在不降低图像质量的情况下截取屏幕截图/将 UIView
内容保存到图像中?
这是我的代码片段:
UIGraphicsBeginImageContext(self.myView.frame.size);
[self.myview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
最佳答案
尝试以下代码:
UIGraphicsBeginImageContextWithOptions(YourView.bounds.size, NO, 0);
[YourView drawViewHierarchyInRect:YourView.bounds afterScreenUpdates:YES];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这段代码工作得很好......!!!
关于ios - 如何在不降低其质量的情况下保存 UIView 内容(屏幕截图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24649428/