Android Learning image compression, high compression and low distortion

Source: Internet
Author: User

Once in the mobile phone to upload pictures. Directly capture the camera's original image upload, the original size is generally 1~2m. Therefore, upload a more than 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 information. Then try to change a picture compression method. The test is good. The compression effect is very ideal, mainly distortion is not obvious. Share it here.

The following code is directly on:

/** * Upload the server when the image is called the following method compressed after saving to the temporary directory image compression less than 200KB. Distortion is not obvious * * @param path * @return * @throws ioexception */public static Bitmap revitionimagesize (String path) throws Ioexc eption {Bufferedinputstream in = new Bufferedinputstream (new FileInputStream (path)); 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 thumbnail size of a fraction of the original picture size of one//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;}

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: 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.