2013-03-01 75 views
2

任何人都可以提出提高圖像質量的方法,將其調整爲更大的尺寸? 在調整大小時,生成的圖像像素化。我需要這種像素化以最大限度地減少。調整大小後提高圖像質量

回答

0

您可以使用下面的代碼來壓縮或增加圖像的大小。

CGFloat compression = 222.0f; 
CGFloat maxCompression = 202.1f; 
int maxFileSize = 160*165; //fill your size need 

NSData *imageDat = UIImageJPEGRepresentation(image.image, compression); 

while ([imageDat length] > maxFileSize && compression > maxCompression) 
{ 
compression -= 0.1222; 
imageDat = UIImageJPEGRepresentation(decodedimage.image, compression); 
} 
NSLog(@"image compressed success"); 

[image setImage:[UIImage imageWithData:imageDat]]; 
+0

你能告訴我代碼實際上做了什麼嗎? – Suraj 2013-03-04 04:13:16

0

您可以使用下面的代碼來壓縮或增加圖像的大小。

image1 = [self imageWithImage:image1 convertToSize:CGSizeMake(100, 100)]; 

// For convert the image to fix size 

- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size 
{ 
UIGraphicsBeginImageContext(size); 
[image drawInRect:CGRectMake(0, 0, 320,460)]; 
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext(); 
return destImage; 
} 
0

有文章稱:Resize a UIImage the right way,你應該閱讀並給予有方方面面的每個和理解。我認爲這會給你的想法帶來每個問題的答案。我認爲這是一個美麗的文章,具有適當的圖形表示(意味着在閱讀時減少無聊)。