IOS: proportional compression screenshot code, ios proportional compression screenshot

Source: Internet
Author: User

IOS: proportional compression code, ios proportional Compression

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 // and set it to the currently used context 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 UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext (); [newImage retain] from the current context; // make the current context output the stack UIGraphicsEndImageContext (); return newImage ;}

 


The image will be compressed to 200x200

Proportional compression means that the ratio of length to width remains unchanged.
For example, if the original image is 800*600, and you change the length to 400, then the corresponding width is 300.
I don't understand.

For a 120x90 image, how can the new image generated by the program equal to compression be not distorted?

How do you compress it? Is it possible that PHP is not professional in graph processing to call the GD library function of PHP.

I have installed an imagemagicsoftware, which can use the command line to call the console program convert.exe to compress and convert images. I think it works well.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.