List of usage examples for android.graphics Matrix Matrix
public Matrix()
From source file:Main.java
/** * scale image/*from www. java 2s. co m*/ * @param src * @param scaleWidth * @param scaleHeight * @return */ public static Bitmap scaleImage(Bitmap src, float scaleWidth, float scaleHeight) { if (src == null) { return null; } Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap getFlippedBitmap(Resources res, int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true;//from ww w . jav a 2s .c om //Below line is necessary to fill in opt.outWidth, opt.outHeight Bitmap b = BitmapFactory.decodeResource(res, resId, opt); b = Bitmap.createBitmap(opt.outWidth, opt.outHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(b); Matrix flipHorizontalMatrix = new Matrix(); flipHorizontalMatrix.setScale(-1, 1); flipHorizontalMatrix.postTranslate(b.getWidth(), 0); Bitmap bb = BitmapFactory.decodeResource(res, resId); canvas.drawBitmap(bb, flipHorizontalMatrix, null); return b; }
From source file:Main.java
public static void drawBitmapCenter(Canvas canvas, float f, float f1, float f2, boolean flag, boolean flag1, Bitmap bitmap, Paint paint) { if (flag) {/* w w w . j a v a 2 s . co m*/ f -= (f2 * (float) bitmap.getWidth()) / 2.0F; } if (flag1) { f1 -= (f2 * (float) bitmap.getHeight()) / 2.0F; } Matrix matrix = new Matrix(); matrix.setScale(f2, f2); matrix.postTranslate(f, f1); canvas.drawBitmap(bitmap, matrix, paint); }
From source file:Main.java
public static Drawable zoomDrawable(Drawable drawable, int w, int h) { if (null == drawable || w < 0 || h < 0) { return null; }/*from w w w .ja va 2 s . com*/ try { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap oldbmp = drawableToBitmap(drawable); Matrix matrix = new Matrix(); float scaleWidth = 1; float scaleHeight = 1; if (w > 0) { scaleWidth = ((float) w / width); } if (h > 0) { scaleHeight = ((float) h / height); } matrix.postScale(scaleWidth, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); return new BitmapDrawable(newbmp); } catch (Exception e) { return null; } }
From source file:Main.java
public static Bitmap compressBitmap(Bitmap bitmap, int width, int height, boolean isAdjust) { if (bitmap.getWidth() > width || bitmap.getHeight() > height) { float scaleX = new BigDecimal(width).divide(new BigDecimal(bitmap.getWidth()), 4, BigDecimal.ROUND_DOWN) .floatValue();/* w ww .ja v a 2 s. c om*/ float scaleY = new BigDecimal(height) .divide(new BigDecimal(bitmap.getHeight()), 4, BigDecimal.ROUND_DOWN).floatValue(); if (isAdjust) { scaleX = (scaleX < scaleY ? scaleX : scaleY); scaleY = scaleX; } Matrix matrix = new Matrix(); matrix.postScale(scaleX, scaleY); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return bitmap; }
From source file:Main.java
public static Bitmap rotate(Bitmap bitmap, int angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle);//from w w w . jav a2 s.c om return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap reverseByVertical(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.preScale(1, -1);/* w w w . ja v a 2 s .c o m*/ return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); }
From source file:Main.java
public static Bitmap reverseByHorizontal(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.preScale(-1, 1);//w w w . java 2s . c o m return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); }
From source file:Main.java
public static Bitmap zoom(Bitmap bitmap, float sf) { Matrix matrix = new Matrix(); matrix.postScale(sf, sf);/*from w w w . j ava2 s . co m*/ return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
/** * Scale a bitmap and correct the dimensions * * @param bitmap Bitmap to scale/*w ww . ja va 2 s .com*/ * @param width width for scaling * @param height height for scaling * @param orientation Current orientation of the Image * @return Scaled bitmap */ public static Bitmap getScaledBitmap(Bitmap bitmap, int width, int height, int orientation) { Matrix m = new Matrix(); m.setRectToRect(new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), new RectF(0, 0, width, height), Matrix.ScaleToFit.CENTER); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { m.postRotate(ORIENTATION_90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { m.postRotate(ORIENTATION_180); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { m.postRotate(ORIENTATION_270); } return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); }