List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.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 = pixels; paint.setAntiAlias(true);//from www. j a v a 2 s . c o m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap combineTwoBitmaps(Bitmap background, Bitmap foreground) { Bitmap combinedBitmap = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());/* w ww. jav a2 s . com*/ 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 bitmap2Round(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);/*from w w w.ja va 2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); 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 getRounded(Bitmap bm, int cornerRadiusPx) { int w = bm.getWidth(); int h = bm.getHeight(); Bitmap bmOut = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmOut); Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w . j a va 2s . c o m*/ paint.setColor(0xff424242); Rect rect = new Rect(0, 0, w, h); RectF rectF = new RectF(rect); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, cornerRadiusPx, cornerRadiusPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bm, rect, rect, paint); return bmOut; }
From source file:Main.java
public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width == height) return bitmap; int size = Math.min(width, height); Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap)); Canvas canvas = new Canvas(target); canvas.translate((size - width) / 2, (size - height) / 2); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); if (recycle)/*from w ww . j a v a 2 s. c o m*/ bitmap.recycle(); return target; }
From source file:Main.java
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); 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 = pixels; paint.setAntiAlias(true);/*from w ww . jav a 2s. 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 zoomBitmap(Bitmap source, float w, float h) { int height = source.getHeight(); int width = source.getWidth(); Matrix matrix = new Matrix(); matrix.postScale(w / width, h / height); Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); return bitmap; }
From source file:Main.java
/** * create a circle from cutout from a bitmap. * does not alter sizes./*from ww w . ja v a 2 s . co m*/ * * @param bitmap the bitmap * @see #cutCircleFromBitmap(String, int) * @return a bitmap circle cutout */ public static Bitmap roundBitMap(Bitmap bitmap) { Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(shader); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); return circleBitmap; }
From source file:Main.java
public static Bitmap handleImageNegative(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;/* w w w .j a v a2 s .c o m*/ int r, g, b, a; Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888); int[] oldPx = new int[width * height]; int[] newPx = new int[width * height]; bm.getPixels(oldPx, 0, width, 0, 0, width, height); for (int i = 0; i < width * height; i++) { color = oldPx[i]; r = Color.red(color); g = Color.green(color); b = Color.blue(color); a = Color.alpha(color); r = 255 - r; g = 255 - g; b = 255 - b; if (r > 255) { r = 255; } else if (r < 0) { r = 0; } if (g > 255) { g = 255; } else if (g < 0) { g = 0; } if (b > 255) { b = 255; } else if (b < 0) { b = 0; } newPx[i] = Color.argb(a, r, g, b); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; }
From source file:Main.java
public static Bitmap scaleDown(Bitmap bmp, float maxImgSize, boolean filter) { float ratio = Math.min((float) maxImgSize / bmp.getWidth(), (float) maxImgSize / bmp.getHeight()); int width = Math.round((float) ratio * bmp.getWidth()); int height = Math.round((float) ratio * bmp.getHeight()); return Bitmap.createScaledBitmap(bmp, width, height, filter); }