List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
/** * Adds the white border to the specifed bitmap image using specified border size. * /*from ww w. jav a2 s . c o m*/ * @param bmp to add border * @param borderSize * @return bitmap image with border. */ public static Bitmap addWhiteBorder(Bitmap bmp, int borderSize, int imgSize) { Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig()); Canvas canvas = new Canvas(bmpWithBorder); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bmp, borderSize, borderSize, null); return bmpWithBorder; }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bmp, float degree) { Matrix matrix = new Matrix(); matrix.postRotate(degree);//from ww w . j a v a 2 s .co m return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); }
From source file:Main.java
public static double getAspectRatio(Bitmap bitmap) { if (bitmap == null) throw new IllegalArgumentException("bitmap is null"); return (double) bitmap.getWidth() / (double) bitmap.getHeight(); }
From source file:Main.java
/** * Scale down the bitmap in order to make color analysis faster. Taken from Palette. *//*from www .ja va2 s . co m*/ private static Bitmap scaleBitmapDown(@NonNull Bitmap bitmap) { final int CALCULATE_BITMAP_MIN_DIMENSION = 100; final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight()); if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) { // If the bitmap is small enough already, just return it return bitmap; } final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension; return Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * scaleRatio), Math.round(bitmap.getHeight() * scaleRatio), false); }
From source file:Main.java
public static Bitmap addPadding(Bitmap bmp, int color) { if (bmp == null) { return null; }//from w w w . j av a2s. com int biggerParam = Math.max(bmp.getWidth(), bmp.getHeight()); Bitmap bitmap = Bitmap.createBitmap(biggerParam, biggerParam, bmp.getConfig()); Canvas canvas = new Canvas(bitmap); canvas.drawColor(color); int top = bmp.getHeight() > bmp.getWidth() ? 0 : (bmp.getWidth() - bmp.getHeight()) / 2; int left = bmp.getWidth() > bmp.getHeight() ? 0 : (bmp.getHeight() - bmp.getWidth()) / 2; canvas.drawBitmap(bmp, left, top, null); return bitmap; }
From source file:Main.java
public static Bitmap changeImageColor(Bitmap sourceBitmap, int color) { Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1); Paint p = new Paint(); p.setColor(color);/*from w w w.java 2 s.com*/ ColorFilter filter = new LightingColorFilter(color, 1); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(resultBitmap, 0, 0, p); return resultBitmap; }
From source file:Main.java
public static float[] convertViewXYintoBitmapXY(int height, int weight, Bitmap bitmap, float x, float y) { float imgHeight = height; float imgWidth = weight; float bmHeight = bitmap.getHeight(); float bmWidth = bitmap.getWidth(); float WidthRatio = bmWidth / imgWidth; float HeightRatio = bmHeight / imgHeight; float BitmapPixelX = x * WidthRatio; float BitmapPixelY = y * HeightRatio; float[] bitmapXY = new float[] { BitmapPixelX, BitmapPixelY }; return bitmapXY; }
From source file:Main.java
public static Bitmap rotate(int angle, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate((float) angle); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap getCircleBitmap(Context context, Bitmap src, float radius) { radius = dipTopx(context, radius);/*from w w w . jav a 2 s. c o m*/ int w = src.getWidth(); int h = src.getHeight(); int canvasW = Math.round(radius * 2); Bitmap bitmap = Bitmap.createBitmap(canvasW, canvasW, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Path path = new Path(); path.addCircle(radius, radius, radius, Path.Direction.CW); canvas.clipPath(path); Paint paint = new Paint(); paint.setAntiAlias(true); Rect srcRect = new Rect(0, 0, w, h); Rect dstRect = new Rect(0, 0, canvasW, canvasW); canvas.drawBitmap(src, srcRect, dstRect, paint); return bitmap; }
From source file:Main.java
public static Bitmap rotateBitmap(int degree, Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postRotate((float) degree); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }