不清晰写法
- (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;
}
补充说明
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
size——同UIGraphicsBeginImageContext
opaque——透明开关,如果图形完全不用透明,设置为YES以优化位图的存储。
scale—–缩放因子:设为0后,系统就会自动设置正确的比例了