Android Learning image compression, high compression and low distortion

Source: Internet
Author: User

In the past to do the mobile phone upload pictures, direct access to the camera to capture the original image upload, the original size is generally 1~2m, so upload a waste of resources, some scenes also need to upload more than one picture, so recently looked at a lot of predecessors written about the image processing, and then try to change a picture compression method. The test is also good, the compression effect is ideal, mainly distortion is not obvious. Share it here.

Directly below the code:

/** * Upload the server when the image is called the following method compressed after saving to the temporary folder image compressed less than 200KB, distortion is not obvious * * @param path * @return * @throws ioexception */public static Bit Map Revitionimagesize (String path) throws IOException {Bufferedinputstream in = new Bufferedinputstream (new FileInputStream (new File)); Bitmapfactory.options Options = new Bitmapfactory.options (); options.injustdecodebounds = true; Bitmapfactory.decodestream (in, null, options); In.close (); int i = 0; Bitmap Bitmap = null;//Options.injustdecodebounds=true then will not return the actual Bitmap object, do not allocate memory space but can get some decoding boundary information, such as picture size information// Outheight (image original height) and outwidth (original width of the picture)//insamplesize represents a fraction of the size of the original picture//Options.outwidth >> I (right shift operator)  Represents: outwidth/(2^i) while (true) {if ((options.outwidth >> i <=) && (options.outheight >> i <= ) {in = new Bufferedinputstream (new FileInputStream (path)), options.insamplesize = (int) Math.pow (2.0D, i) ; The power operation I is several square options.injustdecodebounds = False;bitmap = Bitmapfactory.decodestream (in, null, options); i + = 1;} REturn bitmap;} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Learning image compression, high compression and low distortion

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.