+(UIImage *)thumbImageWithImage:(UIImage *)scImg limitSize:(CGSize)limitSize
{
if (scImg.size.width <= limitSize.width && scImg.size.height <= limitSize.height) {
return scImg;
}
CGSize thumbSize;
if (scImg.size.width / scImg.size.height > limitSize.width / limitSize.height) {
thumbSize.width = limitSize.width;
thumbSize.height = limitSize.width / scImg.size.width * scImg.size.height;
}
else {
thumbSize.height = limitSize.height;
thumbSize.width = limitSize.height / scImg.size.height * scImg.size.width;
}
UIGraphicsBeginImageContext(thumbSize);
[scImg drawInRect:(CGRect){CGPointZero,thumbSize}];
UIImage *thumbImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return thumbImg;
}
//调用
UIImage *thumbImg = [CustomImage thumbImageWithImage:desImage limitSize:CGSizeMake(100, 80)];