2012-09-26 68 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