2012-09-26 66 views
0

在我的应用程序中,我想要高品质的图像。图片从Facebook好友列表中加载。当图像以较小尺寸(50 * 50)加载时,其质量很好。但是,当我尝试以更大尺寸(280 * 280)获得该图像时,图像质量下降。iPhone中的高品质圆角图像

enter image description here

对于圆角在做这样的:

self.mImageView.layer.cornerRadius = 10.0; 
self.mImageView.layer.borderColor = [UIColor blackColor].CGColor; 
self.mImageView.layer.borderWidth = 1.0; 
self.mImageView.layer.masksToBounds = YES; 

对于使用下面的代码获取图像M:

self.mImageView.image = [self imageWithImage:profileImage scaledToSize:CGSizeMake(280, 280)]; 

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { 
UIGraphicsBeginImageContextWithOptions(newSize, YES,0.0); 
CGContextRef context = CGContextRetain(UIGraphicsGetCurrentContext()); 
CGContextTranslateCTM(context, 0.0, newSize.height); 
CGContextScaleCTM(context, 1.0, -1.0); 
CGContextSetInterpolationQuality(context, kCGInterpolationLow); 
CGContextSetAllowsAntialiasing (context, TRUE); 
CGContextSetShouldAntialias(context, TRUE); 
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, newSize.width, newSize.height),image.CGImage); 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext(); 
return newImage; 

}

我检查我的代码几次,但无法弄清楚如何使图像完美。那么,大家如何提高图像质量呢? Thanx提前...

回答

1

...图像质量下降。

图像的'质量'仍然存在。 (从技术上讲,您通过调整大小来引入少量错误,但这不是真正的问题...)

因此,您想要将50x50px图像缩放为280x280px?信号/细节不存在于源信号中。理想情况下,您可以下载更适合尺寸的图像,以显示您想要显示的尺寸。

如果这不是一个选项,您可以通过适当的重采样和/或插值来减少像素化。这将简单地消除程序放大5.6倍的像素 - 图像看起来像是像素化和模糊的交叉(请参阅CGContextSetAllowsAntialiasing,CGContextSetShouldAntialias,CGContextSetInterpolationQuality以及使用石英完成此操作的相关API)。

+0

所以CSI一直在骗我? – jrturton

+0

@jrturton“CSI”? – justin

+0

@justin,我已经根据你的建议改变了我的代码,即使现在图像正在模糊..任何想法,如果我错过了什么? – iCoder4777