2014-01-15 105 views
0

我正在处理我的照片应用程序,并且出现质量较差的最终保存图像时出现问题。我不知道如何才能使图像质量与我在屏幕上看到的图像质量相匹配(保存到相机胶卷之前)。当我打开保存的图像时,它是像素化/模糊的。这里是我的代码,任何见解将不胜感激:保存后UIImage质量差

CGRect grabRect ;  
    if (self.view.frame.size.height==460) { 
     grabRect = CGRectMake(30,50,260,257); 
    } 
    else{ 
     grabRect = CGRectMake(3,50,314,315); 
    } 
    //for retina displays 
    NSLog(@"save......"); 
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 
     UIGraphicsBeginImageContextWithOptions(grabRect.size, NO, [UIScreen mainScreen].scale); 
    } else { 
     UIGraphicsBeginImageContext(grabRect.size); 
    } 
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(ctx, -grabRect.origin.x, -grabRect.origin.y); 
    [self.view.layer renderInContext:ctx]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 
+0

对不起,我试过了,它没有任何区别。 – dfox

+0

你是说这是模糊*之前*你保存到相机胶卷,或者在你将它保存到相机胶卷并使用iOS Pictures应用程序打开它*然后*它看起来模糊? –

+0

我保存到相机胶卷后。在应用程序中完全没问题,但保存并在相机胶卷中打开时质量会下降。这不是很模糊,只是一点点,但足以让我烦恼。 – dfox

回答

0

我认为这一行是问题。

UIGraphicsBeginImageContextWithOptions(grabRect.size,NO,[UIScreen mainScreen] .scale);

应该是 UIGraphicsBeginImageContextWithOptions(grabRect.size,NO,0);

我可能是错的,但我认为,只需将比例设置为0或0.0即可使用屏幕的默认比例。

+0

已经尝试过了:(没有区别 – dfox

+0

将比例设置为'0'意味着使用当前屏幕的比例,要么给出相同的值。 – rmaddy