来自图像选择器的UIImage模糊

时间:2013-08-19 22:17:17

标签: iphone ios uiimage

我知道这个问题已被问过很多次,但无法弄清楚为什么我的UIImage仍然模糊不清。

我做了什么:

尽管如此,屏幕上显示的UIImage仍然有点模糊。我有什么想法吗?

代码:

UIImage *gotImage = [info objectForKey:UIImagePickerControllerOriginalImage];

float scale = (self.view.frame.size.width)/(imageToResize.size.width);
imageToResize = [imageToResize resizedImage:CGSizeMake(scale * imageToResize.size.width, scale * imageToResize.size.height) interpolationQuality:kCGInterpolationHigh];

UIImageView *background = [[UIImageView alloc] initWithImage:imageToResize];
background.contentMode = UIViewContentModeScaleAspectFit;
background.frame = CGRectIntegral(background.frame);
[self.view addSubview:background];

2 个答案:

答案 0 :(得分:0)

您可能尝试在UIImageView图层上设置光栅化。

原因是,您正在选择原始图像,这取决于设备可以是1000像素。然后使用纵横比例将它压扁。没有光栅化来平滑图像。

这是我的猜测。没有设备信息,您的问题很难回答。

答案 1 :(得分:0)

管理好了解 - 我添加了两行:

UIImage *gotImage = [info objectForKey:UIImagePickerControllerOriginalImage];

float scale = (self.view.frame.size.width * [[UIScreen mainScreen] scale] )/imageToResize.size.width; //Changed line
imageToResize = [imageToResize resizedImage:CGSizeMake(scale * imageToResize.size.width, scale * imageToResize.size.height) interpolationQuality:kCGInterpolationHigh];

UIImage *testImage = [UIImage imageWithCGImage:blurredImage.CGImage scale:[[UIScreen mainScreen] scale] orientation:blurredImage.imageOrientation]; //Changed line
UIImageView *background = [[UIImageView alloc] initWithImage:testImage]; 

background.contentMode = UIViewContentModeScaleAspectFit;
background.frame = CGRectIntegral(background.frame);
[self.view addSubview:background];