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