List of utility methods to do Bitmap Scale
Bitmap | getScalBitmap(Context context, Uri uri, int destW, int destH) get Scal Bitmap if (uri == null) return null; InputStream in = null; try { in = context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); return null; ... |
Bitmap | getScalBitmap(String file, int destW, int destH) get Scal Bitmap if (file == null) return null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bm = BitmapFactory.decodeFile(file, options); options.inJustDecodeBounds = false; float blW = (float) options.outWidth / destW; float blH = (float) options.outHeight / destH; ... |
Bitmap | getScaledBitmap(Bitmap bitmap, int width, int height) get Scaled Bitmap return bitmap.createScaledBitmap(bitmap, width, height, false);
|
Bitmap | getScaledBitmapByHeight(Bitmap bm, int newHeight) get Scaled Bitmap By Height int width = bm.getWidth(); int height = bm.getHeight(); int newWidth = (width * newHeight) / height; Bitmap scaledBitmap = Bitmap.createScaledBitmap(bm, newWidth, newHeight, false); bm.recycle(); return scaledBitmap; |
Bitmap | scaleBitmap(Bitmap bitmap, int dstWidth, int dstHeight) scale Bitmap int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) dstWidth / w); float scaleHeight = ((float) dstHeight / h); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); |
Bitmap | scaleBitmap(Bitmap bitmap, int targetwidth) scale Bitmap int imageWidth = targetwidth; if (bitmap != null && (bitmap.getWidth() < imageWidth || bitmap.getHeight() < imageWidth)) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); int min = width; if (width > height) { min = height; ... |
byte[] | scaleBitmapIfNeededToSize(Bitmap bitmap, long size) scale Bitmap If Needed To Size byte[] data = null; try { float width = bitmap.getWidth(); float height = bitmap.getHeight(); data = bmpToByteArray(bitmap, false); float des = data.length; des = des / size; if (des <= 1) { ... |
Bitmap | scaleBitmapKeepRatio(Bitmap bitmap, int dstWidth, int dstHeight) scale Bitmap Keep Ratio int w = bitmap.getWidth(); int h = bitmap.getHeight(); float ratio = ((float) w) / h; if (dstWidth > dstHeight) { dstWidth = (int) (dstHeight * ratio); } else { dstHeight = (int) (dstWidth / ratio); return scaleBitmap(bitmap, dstWidth, dstHeight); |
Bitmap | scaleToTextSize(Bitmap bmp, float textSize) scale To Text Size int bmpHeight = bmp.getHeight(); if (textSize > 0 && textSize != bmp.getHeight()) { float scale = textSize / (float) bmpHeight; bmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() * scale), (int) (bmpHeight * scale), true); return bmp; ... |
Bitmap | scaleToScreen(Activity activity, Bitmap bitmap) scale To Screen DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int intScreenWidth = dm.widthPixels; int intScreenHeight = dm.heightPixels; return Bitmap.createScaledBitmap(bitmap, intScreenWidth, intScreenHeight, true); |