ObjectiveC 图片压缩
程序员文章站
2024-01-15 19:25:04
...
- (NSData *)resizeWithImage:(UIImage*)image scale:(CGFloat)scale compression:(CGFloat)compression
{
CGSize newSize = CGSizeMake(image.size.width * scale, image.size.height * scale);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return UIImageJPEGRepresentation(newImage, compression);
}
转载于:https://my.oschina.net/nbren/blog/142137