2012-03-28 15 views

回答

1

您可以嘗試自己進行計算:

//Your image 
UIImage *image; 
//Your imageView; 
UIImageView *imageView; 
int width, height; 
float aspectRatio; 
if (image.size.height > image.size.width) 
{ 
    height = imageView.frame.size.height; 
    aspectRatio = image.size.height/height; 
    width = image.size.width/aspectRatio; 
} 
else 
{ 
    width = imageView.frame.size.width; 
    aspectRatio = image.size.width/width; 
    height = image.size.height/aspectRatio; 
} 
+0

我相信這隻適用於平方圖像的意見。例如;圖像視圖爲320 x 416.圖像可能爲640 x 820.這將縮小,新的寬度將爲320,而高度會稍微偏離416 - 不是圖像視圖的整個高度。我正在研究更強大的解決方案。 – Patrick 2013-01-04 16:17:20

2
CGSize size=CGSizeMake(79, 84);//set the width and height 
      UIGraphicsBeginImageContext(size); 
      [image drawInRect:CGRectMake(0,0,size.width,size.height)]; 
      UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
//here is the scaled image which has been changed to the size specified 
      UIGraphicsEndImageContext(); 

這個工程肯定的,不要忘了導入QuartzCore框架..

有一個幸福的編碼(^_^) ....

相關問題