Bitmap Compress is an official picture of the quality of compression, through the experiment to learn the characteristics of this compression is as follows:
-
It is image quality compression, does not change the resolution of the picture
-
Bitmap.compress (Bitmap.CompressFormat.JPEG, option, BOS);
Three parameter description, 1. Image Compressed format 2. Picture compression ratio 3. Data obtained after compression
-
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