【问题标题】:Loss of quality passing images from viewcontroller iOS来自视图控制器 iOS 的质量传递图像丢失
【发布时间】:2015-07-30 15:08:06
【问题描述】:

我正在开发一个应用程序,允许用户在他们的照片上添加蒙版,该应用程序运行良好,但我注意到一个问题,我不知道为什么,但图像质量下降。 我正在使用这种方法将图像传递给视图控制器:

   AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

//SETTO STICKERS
UIGraphicsBeginImageContext(CGSizeMake(_Image.frame.size.width, _Image.frame.size.height));
CGContextRef context = UIGraphicsGetCurrentContext();
[_Image.layer renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

appDelegate.ImageEnded = screenShot;
//Instanzio il viewController della main
LastViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"LastVC"];
//Vado alla main
[self presentModalViewController:VC animated:YES];

并通过使用 appdelegate 从另一个 ViewController 获取图像,这是我的完整应用程序流程:

FirstScreen(ViewController) -> 拍照或从图库中选择 ->
AddMask(ViewController) -> AddStickers(ViewController) -> 最后一个视图控制器(视图控制器)。

【问题讨论】:

    标签: ios objective-c iphone uiviewcontroller photo-gallery


    【解决方案1】:

    通过使用 UIGraphicsBeginImageContext ,比例因子参数默认为 1.0。

    根据docs(强调我的):

    讨论 这个函数相当于调用 UIGraphicsBeginImageContextWithOptions 函数与不透明 参数设置为 NO 和比例因子 1.0

    如果您在视网膜设备上使用它,您会看到一些质量损失。

    您应该使用UIGraphicsBeginImageContextWithOptions,并传入0.0 作为比例因子,这将默认为当前主屏幕的比例因子。 (1 个用于非视网膜设备,2 个用于视网膜设备)。

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 2014-09-13
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多