2012-03-28 13 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

これは、画像の2乗表示にのみ有効です。例えば; 320 x 416の画像ビュー。画像は640 x 820です。これは縮小され、新しい幅は320になりますが、高さは画像ビューの完全な高さではなく416になります。私はより堅牢なソリューションに取り組んでいます。 – Patrick

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枠組みをインポートすることを忘れないでください...

コーディングハッピーをお持ちの(^_^) ....

関連する問題