Analysis and learning of image compression method for Android

Source: Internet
Author: User

Bitmap Compress is an official picture of the quality of compression, through the experiment to learn the characteristics of this compression is as follows:

    1. It is image quality compression, does not change the resolution of the picture

    2. Bitmap.compress (Bitmap.CompressFormat.JPEG, option, BOS);

      Three parameter description, 1. Image Compressed format 2. Picture compression ratio 3. Data obtained after compression

    3. This method will compress the image but, because of the quality compression, bitmap will not become smaller, that is, the memory is still large, the compressed data is really small when used to pay attention to the memory overflow problem

The test method is as follows:

System.out.println ("bitmap==" +bitmap.getbytecount ()); Bytearrayoutputstream BOS = new Bytearrayoutputstream ();//By changing the compression type here, it has different results int option = 100;while (Option > 0) {bit    Map.compress (Bitmap.CompressFormat.JPEG, option, BOS);    System.out.println ("bos=====" + bos.size ());    option-=10; Bos.reset ();} System.out.println ("bitmap==" + Bitmap.getbytecount ()); Bitmap.recycle (); Bytearrayinputstream bis = new Bytearrayinputstream (Bos.tobytearray ()); System.out.println ("bis=====" +bis.available ()); bitmap = Bitmapfactory.decodestream (bis); System.out.println ("bitmap==" +bitmap.getbytecount ()); Imageview.setimagebitmap (bitmap);

If you really want to conserve memory

is to use the following method:

Bytearrayoutputstream out = new Bytearrayoutputstream ();  Image.compress (Bitmap.CompressFormat.JPEG, N, out);  Bitmapfactory.options newopts = new Bitmapfactory.options ();  int be = 2;//Compression ratio, you can calculate the desired scale value by resolution newopts.insamplesize = be;  Bytearrayinputstream ISBM = new Bytearrayinputstream (Out.tobytearray ()); Bitmap Bitmap = Bitmapfactory.decodestream (ISBM, NULL, NULL);


Analysis and learning of image compression method for Android

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.