List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) { Bitmap scaledBitmap;/*ww w.j av a 2 s . co m*/ if (bmp.getWidth() != radius || bmp.getHeight() != radius) { scaledBitmap = ThumbnailUtils.extractThumbnail(bmp, radius - 2, radius - 2); } else { scaledBitmap = bmp; } Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight()); canvas.drawBitmap(scaledBitmap, rect, rect, paint); if (border > 0) { paint.setStrokeWidth(border); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(scaledBitmap.getWidth() / 2, scaledBitmap.getHeight() / 2, scaledBitmap.getWidth() / 2, paint); } return output; }
From source file:Main.java
public static Bitmap rotateImage(Bitmap source, float angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle);// w ww. j av a 2 s . c om return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap doSherpiaEffect(Bitmap src, int depth, double red, double green, double blue) { int width = src.getWidth(); int height = src.getHeight(); Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); final double GS_RED = 0.3; final double GS_GREEN = 0.59; final double GS_BLUE = 0.11; int A, R, G, B; int pixel;/* w w w . ja va 2s . c o m*/ for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { pixel = src.getPixel(x, y); A = Color.alpha(pixel); R = Color.red(pixel); G = Color.green(pixel); B = Color.blue(pixel); B = G = R = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B); R += (depth * red); if (R > 255) { R = 255; } G += (depth * green); if (G > 255) { G = 255; } B += (depth * blue); if (B > 255) { B = 255; } bmOut.setPixel(x, y, Color.argb(A, R, G, B)); } } return bmOut; }
From source file:Main.java
public static Bitmap resizePreservingRatio(Bitmap original, int newWidth, int newHeight) { if (original == null) return null; int originalWidth = original.getWidth(); int originalHeight = original.getHeight(); if (newWidth / (float) originalWidth < newHeight / (float) originalHeight) { newHeight = originalHeight * newWidth / originalWidth; } else {//from w w w . ja va 2s. co m newWidth = originalWidth * newHeight / originalHeight; } return Bitmap.createScaledBitmap(original, newWidth, newHeight, true); }
From source file:Main.java
public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight();/*from w ww . ja va2 s . com*/ width = bmpOriginal.getWidth(); try { Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; } catch (OutOfMemoryError e) { return bmpOriginal; } }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, float angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle);//from w w w . j a v a 2 s. c o m return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
From source file:Main.java
public static final Bitmap complementedBitmapByAlpha(Bitmap bitmap) { if (null == bitmap) { return null; }// w w w . j av a 2 s . c o m int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (width == height) { return bitmap; } int len = width > height ? width : height; Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888); Canvas canvas = new Canvas(output); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setAlpha(0); canvas.drawPaint(paint); if (width > height) { int devide = (width - height) / 2; canvas.drawBitmap(bitmap, 0, devide, paint_comm); } else { int devide = (height - width) / 2; canvas.drawBitmap(bitmap, devide, 0, paint_comm); } return output; }
From source file:Main.java
public static Bitmap reverseByVertical(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.preScale(1, -1);//from w ww . j a va 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);/*from ww w . j av a2 s. c o m*/ return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap bitmap1 = null;// w w w. j a v a2 s .c o m if (bitmap != null) { bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap1); Paint paint = new Paint(); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF rectf = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xffff0000); canvas.drawRoundRect(rectf, 15F, 15F, paint); paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); } return bitmap1; }