List of utility methods to do Bitmap Scale
Bitmap | stretchImage(Bitmap image, int xsize, int ysize) Stretches Bitmap to a scale in each direction. Bitmap data = Bitmap.createBitmap(xsize, ysize, image.getConfig()); Canvas canvas = new Canvas(data); canvas.drawBitmap(image, new Rect(0, 0, image.getWidth(), image.getHeight()), new Rect(0, 0, xsize, ysize), null); return data; |
Bitmap | zoomImg(Bitmap bm, int newWidth, int newHeight) zoom Img int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); ... |
Bitmap | getSmallBitmap(String filePath) get Small Bitmap final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); options.inSampleSize = calculateInSampleSize(options, 320, 480); options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); |
Bitmap | getScaledBitmap(String picturePath, int width, int height) get Scaled Bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(picturePath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; int scaleFactor; if (width > 0 && height > 0) { scaleFactor = Math.min(photoW / width, photoH / height); ... |
Bitmap | cleanStretchImage(Bitmap image, int xsize, int ysize) stretches the middle sections of the image in a cross to avoid the borders looking stretched image = crossStretchImageX(image, xsize);
image = cleanStretchImageY(image, ysize);
return image;
|
Bitmap | cleanStretchImageY(Bitmap image, int ysize) stretches the middle section of the image on the Y axis to avoid the borders looking stretched Bitmap cutout = Bitmap.createBitmap(image.getWidth(), image.getHeight() / 3, image.getConfig()); Canvas cutoutc = new Canvas(cutout); Bitmap temp = Bitmap.createBitmap(image.getWidth(), ysize, image.getConfig()); Canvas tempc = new Canvas(temp); cutoutc.drawBitmap( image, ... |