List of usage examples for android.graphics Matrix postScale
public boolean postScale(float sx, float sy)
From source file:Main.java
public static Drawable resizeImage(Bitmap bitmap, int w, int h) { // load the origial Bitmap Bitmap BitmapOrg = bitmap;/*w w w. j a v a 2s.c o m*/ int width = BitmapOrg.getWidth(); int height = BitmapOrg.getHeight(); int newWidth = w; int newHeight = h; // calculate the scale float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the Bitmap matrix.postScale(scaleWidth, scaleHeight); // if you want to rotate the Bitmap // matrix.postRotate(45); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the Bitmap // to the ImageView, ImageButton or what ever return new BitmapDrawable(resizedBitmap); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; if (scaleWidth < scaleHeight) { scaleHeight = scaleWidth;/* w w w . j a v a2 s. c o m*/ } else { scaleWidth = scaleHeight; } // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // "recreate" the new bitmap return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // CREATE A MATRIX FOR THE MANIPULATION Matrix matrix = new Matrix(); // RESIZE THE BIT MAP matrix.postScale(scaleWidth, scaleHeight); // "RECREATE" THE NEW BITMAP Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); return resizedBitmap; }
From source file:Main.java
public static Bitmap scaleWithRatio(Context c, int res, int max) { Bitmap bmp = imageResourceToBitmap(c, res, max); int width = bmp.getWidth(); int height = bmp.getHeight(); // calculate the scale - in this case = 0.4f float scaleHeight = ((float) max) / height; float scaleWidth = ((float) max) / width; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap and return it return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true); }
From source file:Main.java
/** simply resizes a given drawable resource to the given width and height */ public static Drawable resizeImage(Context ctx, int resId, int iconWidth, int iconHeight) { // load the origial Bitmap Bitmap BitmapOrg = BitmapFactory.decodeResource(ctx.getResources(), resId); int width = BitmapOrg.getWidth(); int height = BitmapOrg.getHeight(); int newWidth = iconWidth; int newHeight = iconHeight; // calculate the scale float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the Bitmap matrix.postScale(scaleWidth, scaleHeight); // if you want to rotate the Bitmap // matrix.postRotate(45); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the Bitmap // to the ImageView, ImageButton or what ever return new BitmapDrawable(resizedBitmap); }
From source file:Main.java
public static Drawable resizeImage(Bitmap bitmap, int newWidth, int newHeight) { Bitmap BitmapOrg = bitmap;//from www .j a v a 2 s .c om int width = BitmapOrg.getWidth(); int height = BitmapOrg.getHeight(); // calculate the scale float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the Bitmap matrix.postScale(scaleWidth, scaleHeight); // if you want to rotate the Bitmap // matrix.postRotate(45); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the Bitmap // to the ImageView, ImageButton or what ever return new BitmapDrawable(resizedBitmap); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap src, int targetWidth, int targetHeight, float degrees) { int srcWidth = src.getWidth(); int srcHeight = src.getHeight(); float scale = getFitScale(targetWidth, targetHeight, srcWidth, srcHeight); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); matrix.postRotate(degrees);/*www .jav a 2 s .c o m*/ return Bitmap.createBitmap(src, 0, 0, srcWidth, srcHeight, matrix, true); }
From source file:Main.java
public static Bitmap zoom(Bitmap source, float wf, float hf) { Matrix matrix = new Matrix(); float sx = wf / source.getWidth(); float sy = hf / source.getHeight(); matrix.postScale(sx, sy); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, float scale) { if (bitmap == null) { return null; }/*from w w w .jav a2 s .c o m*/ int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return result; }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float x = (float) w / width; float y = (float) h / height; matrix.postScale(x, y); Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return zoomBitmap; }