UIImage屏幕截图失去了它的质量
我合并了两个图像,然后通过应用此代码截取屏幕截图:
UIGraphicsBeginImageContext(size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); img_AddText=viewImage; [dragView removeFromSuperview]; imgV_SelectedImg.image=nil; imgV_SelectedImg.image=img_AddText; UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
问题是,当最终的图像失去质量时,模糊。
尝试使用withOptions版本的UIGraphicsBeginImageContext
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
我得到了质量好,屏幕的特定位置的快照。 通过这个代码。
-(UIImage *)takeScreenShot { CGRect grabRect; grabRect = CGRectMake(0,70,320,260); UIGraphicsBeginImageContextWithOptions(grabRect.size, self.view.opaque, 0.0); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(ctx, -grabRect.origin.x, -grabRect.origin.y); [self.view.layer renderInContext:ctx]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return viewImage; }
它给我很好的快照
我已经在UIImage
类上做了一个可以帮助你的类。 它是这样的:
+ (UIImage*)imageWithView:(UIView *)view opaque:(BOOL)opaque bgColor:(UIColor*)bgColor{ UIGraphicsBeginImageContextWithOptions(view.bounds.size, opaque, [[UIScreen mainScreen] scale]); if(!opaque){ [bgColor set]; } [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }
这对我来说可以。 没有发现模糊。 尝试使用它。 如果你仍然有它,那么最有可能的问题是在你的保存代码…
干杯… 🙂
UIGraphicsBeginImageContextWithOptions(size,NO,2.0); 这通过将比例从1.0增加到2.0来解决我的问题
你提供了一个视网膜显示的图像? 你应该检查它。 您可能正在模拟器(视网膜)中运行。
- 要在UIAlertView上显示UIProgressView
- UITextField键盘在加载时阻塞runloop?
- Firebase 3.x – Facebooklogin
- 调整UILabel的大小以适应不同宽度的自定义UITableViewCell中的文本
- 我应该使用多少个测试?
- UISearchBarDelegate showsSearchResultsButton属性的正确用法是什么?
- 打开Facebook页面到facebook应用程序Ios +离子
- Pod Spec Lint CoreSimulator检测到Xcode.app重定位或CoreSimulatorService版本更改
- 如何angular度ios中的uilabel