List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 50; paint.setAntiAlias(true);//from w w w. j a va 2 s . co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getGrayscale(@NonNull Bitmap src) { Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(MATRIX); paint.setColorFilter(filter);/*from w w w .j a v a 2 s. c o m*/ canvas.drawBitmap(src, 0, 0, paint); return dest; }
From source file:Main.java
public static Bitmap roundCorner(Bitmap src, float round) { int width = src.getWidth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0);//w w w . j ava2 s. c o m final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); canvas.drawRoundRect(rectF, round, round, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); return result; }
From source file:Main.java
private static int[] reduceColor(Bitmap bitmap) { sum = 0;/* w ww .java 2s.c o m*/ int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] grayValues = new int[width * height]; int[] pix = new int[width * height]; bitmap.getPixels(pix, 0, width, 0, 0, width, height); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { int x = j * width + i; int r = (pix[x] >> 16) & 0xff; int g = (pix[x] >> 8) & 0xff; int b = pix[x] & 0xff; int grayValue = (r * 30 + g * 59 + b * 11) / 100; sum += grayValue; grayValues[x] = grayValue; } return grayValues; }
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 w w . j a v a 2s . co m 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 toRoundCorner(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true);//from ww w. j av a 2s . c om canvas.drawARGB(0, 255, 255, 255); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:Main.java
/** * draw the image to viewBitmap in fill mode. * @param viewBitmap Bitmap to be displayed on the device. * @param bitmap Bitmap image./*from w w w. j a v a 2 s .c om*/ */ public static void drawImageForFillsMode(final Bitmap viewBitmap, final Bitmap bitmap) { float getSizeW = bitmap.getWidth(); float getSizeH = bitmap.getHeight(); Canvas canvas = new Canvas(viewBitmap); final int width = viewBitmap.getWidth(); final int height = viewBitmap.getHeight(); for (int drawY = 0; drawY <= height; drawY += getSizeH) { for (int drawX = 0; drawX <= width; drawX += getSizeW) { canvas.drawBitmap(bitmap, drawX, drawY, null); } } }
From source file:Main.java
public static Bitmap scale(Bitmap org, float xRate, float yRate) { final int orgWidth = org.getWidth(); final int orgHeight = org.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(xRate, yRate);/*from www .j av a 2s . com*/ return Bitmap.createBitmap(org, 0, 0, orgWidth, orgHeight, matrix, true); }
From source file:Main.java
public static Bitmap combineTwoBitmaps(Bitmap background, Bitmap foreground) { Bitmap combinedBitmap = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());/*from www. j a v a 2 s .co m*/ Canvas canvas = new Canvas(combinedBitmap); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(background, 0, 0, paint); canvas.drawBitmap(foreground, 0, 0, paint); return combinedBitmap; }
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; }