List of usage examples for android.graphics Bitmap createBitmap
public static Bitmap createBitmap(@NonNull DisplayMetrics display, @NonNull @ColorInt int[] colors, int offset, int stride, int width, int height, @NonNull Config config)
From source file:Main.java
/** * scale image/*from ww w. j a v a2 s . c om*/ * * @param org * @param scaleWidth sacle of width * @param scaleHeight scale of height * @return */ public static Bitmap scaleImage(Bitmap org, float scaleWidth, float scaleHeight) { if (org == null) { return null; } Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(org, 0, 0, org.getWidth(), org.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap scaleImage(Bitmap bitmap, int destW, int destH) { if (bitmap == null) { return null; }/*from www .jav a 2 s .c o m*/ int width = bitmap.getWidth(); int height = bitmap.getHeight(); float scaleWidth = ((float) destW) / width; float scaleHeight = ((float) destH) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return scaledBitmap; }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, float scale) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Log.e("ss", "width=" + width); Log.e("ss", "height=" + height); Matrix matrix = new Matrix(); //float scaleWidht = ((float)w / width); //float scaleHeight = ((float)h / height); matrix.postScale(scale, scale);/*from w w w . ja va2 s . com*/ Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newbmp; }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Bitmap newbmp;//from www. java 2s . c o m try { // if (h >= w) { // if (height <= h) { Matrix matrix = new Matrix(); float scaleHeight = ((float) height / h); matrix.postScale(scaleHeight, scaleHeight); newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); return newbmp; // } // } else { // if (width <= w) { // Matrix matrix = new Matrix(); // float scaleWidth = ((float) width / w); // matrix.postScale(scaleWidth, scaleWidth); // newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, // true); // return newbmp; // } // } } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) { int width = bm.getWidth(); int height = bm.getHeight(); int newWidth1 = newWidth; int newHeight1 = newHeight; float scaleWidth = ((float) newWidth1) / width; float scaleHeight = ((float) newHeight1) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); return newbm; }
From source file:Main.java
/** * For rotating images/*from w w w .j a v a2 s . co m*/ * @param bitmap Bitmap to rotate * @param degree Degree amount to rotate * @return */ public static Bitmap rotate(Bitmap bitmap, int degree) { if (bitmap == null) { return null; } int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap bitmap, int reW, int reH) { if (bitmap == null) { return null; }//from w w w. j av a 2 s . c o m int bmpW = bitmap.getWidth(); int bmpH = bitmap.getHeight(); float wScale = reW * 1.0f / bmpW; float hScale = reH * 1.0f / bmpH; float scale = Math.max(wScale, hScale); Matrix matrix = new Matrix(); matrix.setScale(scale, scale); return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrix, true); }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bm, int direction) { Bitmap returnBm;//from w w w. j a va 2s . com int w = bm.getWidth(); int h = bm.getHeight(); Matrix matrix = new Matrix(); if (direction == ROTATE_LEFT) { matrix.postRotate(-90); } else if (direction == ROTATE_RIGHT) { matrix.postRotate(90); } returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true); if (bm != returnBm) { bm.recycle(); } return returnBm; }
From source file:Main.java
/** * Shrink the bitmap to the specified scale. * * @param bitmap to shrink./* w w w .j ava2s . c o m*/ * @param scale the shrink scale, must be < 1.0. * @return the shrunk bitmap. */ public static Bitmap shrink(Bitmap bitmap, float scale) { if (scale >= 1.0f) { return bitmap.copy(bitmap.getConfig(), false); } Matrix matrix = new Matrix(); matrix.postScale(scale, scale); return Bitmap.createBitmap(bitmap, 0, 0, (int) (scale * bitmap.getWidth()), (int) (scale * bitmap.getHeight()), matrix, true); }
From source file:Main.java
public static Bitmap resizeImageByWidth(Bitmap defaultBitmap, int targetWidth) { int rawWidth = defaultBitmap.getWidth(); int rawHeight = defaultBitmap.getHeight(); float targetHeight = targetWidth * (float) rawHeight / (float) rawWidth; float scaleWidth = targetWidth / (float) rawWidth; float scaleHeight = targetHeight / (float) rawHeight; Matrix localMatrix = new Matrix(); localMatrix.postScale(scaleHeight, scaleWidth); return Bitmap.createBitmap(defaultBitmap, 0, 0, rawWidth, rawHeight, localMatrix, true); }