List of utility methods to do Bitmap Scale
Bitmap | scaleImage(Bitmap image, float scale) scales Bitmap to a decimal Bitmap data = Bitmap.createBitmap((int) (image.getWidth() * scale), (int) (image.getHeight() * scale), 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() * scale), (int) (image.getHeight() * scale)), null); return data; ... |
Bitmap | scaleImg(Bitmap bitmap, float scale) scale Img Bitmap resizeBmp = null; try { int bmpW = bitmap.getWidth(); int bmpH = bitmap.getHeight(); Matrix mt = new Matrix(); mt.postScale(scale, scale); resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, mt, true); ... |
Bitmap | scaleImg(Bitmap bitmap, int newWidth, int newHeight) scale Img Bitmap resizeBmp = null; if (bitmap == null) { return null; if (newWidth <= 0 || newHeight <= 0) { throw new IllegalArgumentException("???????????????0"); int srcWidth = bitmap.getWidth(); ... |
Bitmap | scaleImg(File file, int newWidth, int newHeight) scale Img Bitmap resizeBmp = null; if (newWidth <= 0 || newHeight <= 0) { throw new IllegalArgumentException("???????????????0"); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getPath(), opts); int srcWidth = opts.outWidth; ... |
Bitmap | getScaleBitmap(Bitmap origialBitmap, int dstWidth, int dstHeight) get Scale Bitmap Bitmap scaleBitmap = Bitmap.createScaledBitmap(origialBitmap, dstWidth, dstHeight, true); if (origialBitmap != null && !origialBitmap.isRecycled()) { origialBitmap.recycle(); return scaleBitmap; |
Bitmap | getScaleBitmap(Context context, int resId, int dstWidth, int dstHeight) get Scale Bitmap Bitmap origialBitmap = BitmapFactory.decodeResource( context.getResources(), resId); Bitmap scaleBitmap = Bitmap.createScaledBitmap(origialBitmap, dstWidth, dstHeight, true); if (origialBitmap != null && !origialBitmap.isRecycled()) { origialBitmap.recycle(); return scaleBitmap; ... |
Bitmap | getScaleImage(final Bitmap bitmap, final float boundBoxInDp) get Scale Image final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final float xScale = boundBoxInDp / width; final float yScale = boundBoxInDp / height; final float scale = xScale <= yScale ? xScale : yScale; final Matrix matrix = new Matrix(); matrix.postScale(scale, scale); final Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, ... |
Bitmap | generateScaledBitmap(Bitmap bitmap, int width, int height) Generates a bitmap scaled to provided width and height if (bitmap != null) { try { return Bitmap.createScaledBitmap(bitmap, width, height, true); } catch (IllegalArgumentException illegalArgs) { return null; } else { ... |
Bitmap | generateScaledBitmap(Drawable drawable, int width, int height) Generates a bitmap scaled to provided width and height if (drawable != null && drawable instanceof BitmapDrawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); return generateScaledBitmap(bitmap, width, height); } else { return null; |
Bitmap | generateScaledBitmap(byte[] bitMapData, int width, int height) Generates a bitmap scaled to provided width and height if (bitMapData != null) { try { Bitmap bitmap = BitmapFactory.decodeByteArray(bitMapData, 0, bitMapData.length); return generateScaledBitmap(bitmap, width, height); } catch (ArrayIndexOutOfBoundsException indexOutOfBounds) { return null; } catch (IllegalArgumentException illegalArgs) { ... |