不清晰寫法
- (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{
UIGraphicsBeginImageContext(reSize);
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return reSizeImage;
}
修改過后
-(UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{
//instead of UIGraphicsBeginImageContext(reSize);
UIGraphicsBeginImageContextWithOptions(reSize, YES, 0);
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return reSizeImage;
}
補(bǔ)充說明
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
size——同UIGraphicsBeginImageContext
opaque——透明開關(guān),如果圖形完全不用透明,設(shè)置為YES以優(yōu)化位圖的存儲。
scale—–縮放因子:設(shè)為0后纽绍,系統(tǒng)就會自動設(shè)置正確的比例了