Android often encounters the need to zoom in and out of the image, the following list of 3 image scaling methods:
I. Image zoom
1.inSampleSize (sample rate)
Advantages: High efficiency, fast parsing speed
Disadvantage: The sampling rate insamplesize value can only be 2 of the number of times (for example: insamplesize=15, the actual value is 8;insamplesize=17, the actual value is 16, the actual value will be 2 of the second-party settlement), Therefore, the method does not accurately specify the size of the picture
2.Matrix
Pros: You can specify the zoom size of the picture precisely
Disadvantage: is generated on the basis of the original bitmap, accounting for memory, low efficiency.
3.ThumbnailUtils
The 2.2 new class, in effect, combines the two methods described above and encapsulates them.
Two. Image compression
Often picture compression is to save network traffic, network transmission, generally need to compress the picture into byte[] array.
public static byte[] Bitmaptobyte (Bitmap Bitmap) {Bytearrayoutputstream BAOs = new Bytearrayoutputstream (); Bitmap.compress (Compressformat.png, BAOs);//The 80 parameter indicates the scale to compress return Baos.tobytearray ();}
Android image scaling, compression summary (Insamplesize,matrix comparison)