iphone图片等比缩放

iphone图片等比缩放

UIImage *img = imgView.image;

 

int h = img.size.height;

int w = img.size.width;

if(h <= 320 && w <= 480)

{

imgView.image = img;

}

else 

{

float b = (float)320/w < (float)480/h ? (float)320/w : (float)480/h;

CGSize itemSize = CGSizeMake(b*w, b*h);

UIGraphicsBeginImageContext(itemSize);

CGRect imageRect = CGRectMake(0, 0, b*w, b*h);

[img drawInRect:imageRect];

imgView.image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

原文地址:https://www.cnblogs.com/zhwl/p/2850747.html