Android Development Compressed Picture

Source: Internet
Author: User

Private Bitmap imagezoom (int position, Bitmap Bitmap) {
Picture allows maximum space
Double maxSize = 2000.00;
Double bitmapsize = Bitmap.getbytecount ()/1024;
LOG.D ("Derrick", "Bitmap 0 =" +bitmapsize+ ", index =" +position ");
if (Bitmapsize < maxSize) {
return BITMAP;
}
if (Bitmapsize > MaxSize) {
Gets how many times the bitmap size is allowed for the maximum size
Double scale = bitmapsize/maxsize;
Start compression Here the square root is used to compress the width and height of the corresponding square root fold (1. Keep the scale and height consistent with the original bitmap ratio, and compress to the maximum size of the space)
Bitmap result = Zoomimage (Bitmap, Bitmap.getwidth ()/math.sqrt (scale), bitmap.getheight ()/math.sqrt (scale));
LOG.I ("Derrick", "Bitmap 1 =" +result.getbytecount ()/1024 + ", index =" +position ");
return result;
}
return BITMAP;
}
Private Bitmap Zoomimage (Bitmap bgimage, double newwidth,double newheight) {
Get the width and height of this picture
Float width = bgimage.getwidth ();
float height = bgimage.getheight ();
Create a Matrix object for manipulating pictures
Matrix matrix = new Matrix ();
Calculate the wide and high zoom rate
float ScaleWidth = ((float) newwidth)/width;
float ScaleHeight = ((float) newheight)/height;
Zoom picture Action
Matrix.postscale (ScaleWidth, ScaleHeight);
Bitmap Bitmap = Bitmap.createbitmap (bgimage, 0, 0, (int) width, (int) height, matrix, true);
return bitmap;
}

Android Development Compressed Picture

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.