IOS moderately compressed code
Compress and enlarge an image according to the desired size, and finally extract the required size. I don't know if it is clear. That's what it means anyway!
+ (UIImage *) compressImageWith :( UIImage *) image width :( float) width height :( float) height
{
Float imageWidth = image. size. width;
Float imageHeight = image. size. height;
Float widthScale = imageWidth/width;
Float heightScale = imageHeight/height;
// Create a bitmap context
// Set it to the context currently in use
UIGraphicsBeginImageContext (CGSizeMake (width, height ));
If (widthScale> heightScale ){
[Image drawInRect: CGRectMake (0, 0, imageWidth/heightScale, height)];
}
Else {
[Image drawInRect: CGRectMake (0, 0, width, imageHeight/widthScale)];
}
// Create an image with the size changed from the current context
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext ();
[NewImage retain];
// Make the current context output from the stack
UIGraphicsEndImageContext ();
Return newImage;
}