List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
/** * Compares two bitmaps and gives the percentage of similarity * * @param bitmap1 input bitmap 1// w ww. j a v a 2s . com * @param bitmap2 input bitmap 2 * @return a value between 0.0 to 1.0 . Note the method will return 0.0 if either of bitmaps are null nor of same size. * */ public static float compareEquivalance(Bitmap bitmap1, Bitmap bitmap2) { if (bitmap1 == null || bitmap2 == null || bitmap1.getWidth() != bitmap2.getWidth() || bitmap1.getHeight() != bitmap2.getHeight()) { return 0f; } ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes()); bitmap1.copyPixelsToBuffer(buffer1); ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes()); bitmap2.copyPixelsToBuffer(buffer2); byte[] array1 = buffer1.array(); byte[] array2 = buffer2.array(); int len = array1.length; // array1 and array2 will be of some length. int count = 0; for (int i = 0; i < len; i++) { if (array1[i] == array2[i]) { count++; } } return ((float) (count)) / len; }
From source file:Main.java
public static Bitmap scale(Bitmap bitmap, float scale) { if (bitmap == null) { return null; }//from ww w.j a va2 s .c om int width = Math.max(1, (int) (bitmap.getWidth() * scale)); int height = Math.max(1, (int) (bitmap.getHeight() * scale)); return Bitmap.createScaledBitmap(bitmap, width, height, false); }
From source file:Main.java
public static Bitmap handleImageEffect(Bitmap bm, float hue, float saturation, float lum) { Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); ColorMatrix hueMatrix = new ColorMatrix(); hueMatrix.setRotate(0, hue);/* w w w .ja va2 s .com*/ hueMatrix.setRotate(1, hue); hueMatrix.setRotate(2, hue); ColorMatrix saturationMatrix = new ColorMatrix(); saturationMatrix.setSaturation(saturation); ColorMatrix lumMatrix = new ColorMatrix(); lumMatrix.setScale(lum, lum, lum, 1); ColorMatrix imageMatrix = new ColorMatrix(); imageMatrix.postConcat(hueMatrix); imageMatrix.postConcat(saturationMatrix); imageMatrix.postConcat(lumMatrix); paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix)); canvas.drawBitmap(bm, 0, 0, paint); return bmp; }
From source file:Main.java
public static Bitmap cutBitmap(int newWidth, int newHeight, Bitmap bitmap) { if (bitmap == null) { return null; }/*from ww w . j a v a 2 s . c o m*/ if (bitmap.getWidth() > newWidth) { int startX = (bitmap.getWidth() - newWidth) / 2; Bitmap targetBitmap = Bitmap.createBitmap(bitmap, startX, 0, newWidth, newHeight); if (!bitmap.isRecycled()) { bitmap.recycle(); } return targetBitmap; } else if (bitmap.getHeight() > newHeight) { int startY = (bitmap.getHeight() - newHeight) / 2; Bitmap targetBitmap = Bitmap.createBitmap(bitmap, 0, startY, newWidth, newHeight); if (!bitmap.isRecycled()) { bitmap.recycle(); } return targetBitmap; } return bitmap; }
From source file:Main.java
public static Bitmap rotateImageView(int angle, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate(angle);/*from w ww .ja v a 2s . co m*/ return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap rotateDrawable(Context context, @DrawableRes int resId, int angle) { Bitmap bmpOriginal = BitmapFactory.decodeResource(context.getResources(), resId); Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888);/*w w w .j av a2 s.c o m*/ Canvas tempCanvas = new Canvas(bmResult); tempCanvas.rotate(angle - 90, bmpOriginal.getWidth() / 2, bmpOriginal.getHeight() / 2); tempCanvas.drawBitmap(bmpOriginal, 0, 0, null); return bmResult; }
From source file:Main.java
private static Bitmap rotateImageView(int angle, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate(angle);//from w w w . j a v a 2s .c o m return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap createRoundedBitmap(Context context, Bitmap bitmap, int radiusDP) { Bitmap bmp;/*from w w w. j a v a 2 s .c om*/ bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radiusDP, context.getResources().getDisplayMetrics()); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(rect, radius, radius, paint); return bmp; }
From source file:Main.java
public static Bitmap doRotate(Bitmap b, float angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle);//from w w w. j a v a 2s . com b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); return b; }
From source file:Main.java
/** * @param b/*from w w w . j av a 2s. c o m*/ * @param rotateDegree * @return */ public static Bitmap getRotateBitmap(Bitmap b, float rotateDegree) { Matrix matrix = new Matrix(); matrix.postRotate(rotateDegree); int width = b.getWidth(); int height = b.getHeight(); return Bitmap.createBitmap(b, 0, 0, width, height, matrix, false); }