图片压缩核心代码
-(UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize {
// Create a graphics image context
UIGraphicsBeginImageContext(newSize);
// Tell the old image to draw in this new context, with the desired newsize
[image drawInRect: CGRectMake(0,0,newSize.width,newSize.height)];
// Get the new image from the context
UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
// Endthecontext
UIGraphicsEndImageContext();
// Return the new image.
return newImage;
}
图片压缩调用
UIImage*yourImage=[self imageWithImageSimple:image scaledToSize: CGSizeMake(210.0,210.0)];
希望对你有帮助!
网友评论