List of utility methods to do Bitmap Scale
Bitmap | crossStretchImageX(Bitmap image, int xsize) stretches the middle section of the image on the X axis to avoid the borders looking stretched Bitmap cutout = Bitmap.createBitmap((image.getWidth() / 3), image.getHeight(), image.getConfig()); Canvas cutoutc = new Canvas(cutout); Bitmap temp = Bitmap.createBitmap(xsize, image.getHeight(), image.getConfig()); Canvas tempc = new Canvas(temp); cutoutc.drawBitmap(image, new Rect(image.getWidth() / 3, 0, ... |
Bitmap | scaleBitmap(Bitmap bitmap, int width, int height) scale Bitmap long start = System.currentTimeMillis(); if (bitmap == null) { return null; int newWidth = width; int newHeight = height; if (newHeight == 0) { newHeight = (int) (newWidth / (float) bitmap.getWidth() * bitmap ... |
Bitmap | scaleBitmap(String path, int newWidth, int newHeight) scale Bitmap Bitmap bm = BitmapFactory.decodeFile(path); 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, ... |
Bitmap | scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth) scale Clip Bitmap By Circle if (null != src) { Bitmap maskMap = Bitmap.createBitmap(nRadius << 1, nRadius << 1, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(maskMap); canvas.drawARGB(0, 0, 0, 0); Paint ptDrawCircle = new Paint(); ptDrawCircle.setColor(Color.BLACK); ptDrawCircle.setStyle(Style.FILL); ... |
Bitmap | getScaledImageFromUri(Activity activity, Uri uri, int size) get Scaled Image From Uri BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = size; String imagePath = getRealPathFromURI(activity, uri); if (imagePath != null) { Bitmap bitmapImage = BitmapFactory.decodeFile(imagePath, options); return bitmapImage; } else { ... |
Bitmap | imageScale(Bitmap bitmap, int dst_w, int dst_h) image Scale int src_w = bitmap.getWidth(); int src_h = bitmap.getHeight(); float scale_w = ((float) dst_w) / src_w; float scale_h = ((float) dst_h) / src_h; Matrix matrix = new Matrix(); matrix.postScale(scale_w, scale_h); Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix, true); ... |
Bitmap | scaleBitmap(Bitmap bitmap, float scale) scale Bitmap int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newBitmap; |
Bitmap | scaleBitmapDown(Bitmap bitmap) Scale down the bitmap in order to make color analysis faster. final int CALCULATE_BITMAP_MIN_DIMENSION = 100; final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight()); if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) { return bitmap; final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension; ... |
Bitmap | scaleToFit(Bitmap bm, float width_Ratio, float height_Ratio) scale To Fit int width = bm.getWidth(); int height = bm.getHeight(); Matrix matrix = new Matrix(); matrix.postScale((float) width_Ratio, (float) height_Ratio); Bitmap bmResult = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); return bmResult; |
Bitmap | stretchImage(Bitmap image, float xscale, float yscale) Stretches Bitmap to a scale in each direction. Bitmap data = Bitmap.createBitmap( (int) (image.getWidth() * xscale), (int) (image.getHeight() * yscale), image.getConfig()); Canvas canvas = new Canvas(data); canvas.drawBitmap(image, new Rect(0, 0, image.getWidth(), image.getHeight()), new Rect(0, 0, (int) (image.getWidth() * xscale), (int) (image.getHeight() * yscale)), null); ... |