Android image scaling, compression summary (Insamplesize,matrix comparison)

Source: Internet
Author: User

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)

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.