List of usage examples for android.graphics Paint Paint
public Paint()
From source file:Main.java
/** * Create rounded corner bitmap.// ww w .ja v a2s . com * * @param bitmap bitmap. * @return rounded bitmap. */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap source = Bitmap.createScaledBitmap(bitmap, 480, 480, false); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.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, source.getWidth(), source.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = source.getWidth(); paint.setAntiAlias(true); 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(source, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int pixels, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = pixels * densityMultiplier; paint.setAntiAlias(true);/* w w w . j a va2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
From source file:Main.java
/** * Convert bitmap to the grayscale// w ww . ja v a 2 s .c o m * http://androidsnippets.com/convert-bitmap-to-grayscale * * @param bmpOriginal Original bitmap * @return Grayscale bitmap */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { final int height = bmpOriginal.getHeight(); final int width = bmpOriginal.getWidth(); final Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas c = new Canvas(bmpGrayscale); final Paint paint = new Paint(); final ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); final ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx, int w, int h) { Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);//ww w.ja v a2s . c om canvas.drawARGB(0, 0xFF, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), rect, paint); return output; }
From source file:Main.java
public static Bitmap createCircleBitmap(Bitmap bitmap) { if (bitmap == null) { return null; }/*from w w w . j a v a2 s. c o m*/ int bmWidth = bitmap.getWidth(); int bmHeight = bitmap.getHeight(); int side = bmWidth < bmHeight ? bmWidth : bmHeight; int x = (bmWidth - side) / 2; int y = (bmHeight - side) / 2; Bitmap newBm = Bitmap.createBitmap(side, side, Bitmap.Config.ARGB_8888); if (newBm != null) { Canvas canvas = new Canvas(newBm); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); Rect rect = new Rect(0, 0, newBm.getWidth(), newBm.getHeight()); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(newBm.getWidth() / 2, newBm.getHeight() / 2, newBm.getHeight() / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return newBm; } return null; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap input, int dips, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) { Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, w, h); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = dips * densityMultiplier; paint.setAntiAlias(true);/*from www . ja v a2 s . c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square if (squareTL) { canvas.drawRect(0, 0, w / 2, h / 2, paint); } if (squareTR) { canvas.drawRect(w / 2, 0, w, h / 2, paint); } if (squareBL) { canvas.drawRect(0, h / 2, w / 2, h, paint); } if (squareBR) { canvas.drawRect(w / 2, h / 2, w, h, paint); } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); return output; }
From source file:Main.java
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius, int border, int color) { Bitmap scaledBitmap;//from w ww .j av a 2 s . com 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 void drawCropRect(Canvas canvas, RectF bounds) { Paint p = new Paint(); p.setStyle(Paint.Style.STROKE); p.setColor(Color.WHITE);/*from w w w . j a va 2 s. c om*/ p.setStrokeWidth(3); canvas.drawRect(bounds, p); }
From source file:Main.java
public static Bitmap createRoundedBitmap(Context context, Bitmap bitmap, int radiusDP) { Bitmap bmp;/*from ww w . java 2 s . c o m*/ 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
/** * Returns semi-rounded bitmap. This is used for displaying atn promotion images. * //ww w . j a va2s . c o m * @param context * @param input * @return */ public static Bitmap getSemiRoundedBitmap(Context context, Bitmap input) { Bitmap output = Bitmap.createBitmap(input.getWidth(), input.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final float densityMultiplier = context.getResources().getDisplayMetrics().density; final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, input.getWidth(), input.getHeight()); final RectF rectF = new RectF(rect); //make sure that our rounded corner is scaled appropriately final float roundPx = densityMultiplier * 10; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); //draw rectangles over the corners we want to be square canvas.drawRect(input.getWidth() / 2, 0, input.getWidth(), input.getHeight() / 2, paint); canvas.drawRect(input.getWidth() / 2, input.getHeight() / 2, input.getWidth(), input.getHeight(), paint); paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, 0, 0, paint); input.recycle(); return output; }