2
我試圖讓UIImage
的image.size.h
和image.size.w
在UIImageView
的內部與UIViewContentModeScaleAspectFit
開啓。有沒有什麼方法可以在AspectFit集合中找到UIImageView中圖像大小的高度/寬度?
我想調整大小UIImage
大小,而不是原始圖像大小。
可以得到這個值嗎?
我試圖讓UIImage
的image.size.h
和image.size.w
在UIImageView
的內部與UIViewContentModeScaleAspectFit
開啓。有沒有什麼方法可以在AspectFit集合中找到UIImageView中圖像大小的高度/寬度?
我想調整大小UIImage
大小,而不是原始圖像大小。
可以得到這個值嗎?
您可以嘗試自己進行計算:
//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;
}
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框架..
有一個幸福的編碼(^_^) ....
我相信這隻適用於平方圖像的意見。例如;圖像視圖爲320 x 416.圖像可能爲640 x 820.這將縮小,新的寬度將爲320,而高度會稍微偏離416 - 不是圖像視圖的整個高度。我正在研究更強大的解決方案。 – Patrick 2013-01-04 16:17:20