UIGraphics

1、等比缩放

C代码 复制代码 收藏代码

- (UIImage *) scaleImage:(UIImage *)image toScale:(float)scaleSize {

UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize);

[image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];

UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return scaledImage;

}


2、自定义大小

C代码 复制代码 收藏代码

- (UIImage *) reSizeImage:(UIImage *)image toSize:(CGSize)reSize {

UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));

[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];

UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return reSizeImage;

}

你可能感兴趣的:(UIGraphics)