List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:Main.java
/** * Method to remove color in a Bitmap, creating a gray scale image. * * @param bmpOriginal The original Bitmap. * @return The gray scale Bitmap.//from w w w.j a v a 2s. c o m */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { Bitmap bmpGrayscale = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); Paint paint = new Paint(); paint.setAntiAlias(true); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm); paint.setColorFilter(colorMatrixColorFilter); canvas.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }
From source file:Main.java
public static Bitmap formatUserAvatar(Bitmap photo) { int maskColor = 0xff424242; Paint cornerPaint = new Paint(); cornerPaint.setAntiAlias(true); cornerPaint.setColor(maskColor);// w w w . j a va 2 s.c o m Rect roundedCornerRect = new Rect(0, 0, 256, 256); RectF roundedCornerRectF = new RectF(roundedCornerRect); Bitmap roundedCornerBitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888); Canvas roundedCornerCanvas = new Canvas(roundedCornerBitmap); roundedCornerCanvas.drawARGB(0, 0, 0, 0); roundedCornerCanvas.drawRoundRect(roundedCornerRectF, 128, 128, cornerPaint); cornerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); Bitmap scaledBitmap = Bitmap.createScaledBitmap(photo, 256, 256, true); roundedCornerCanvas.drawBitmap(scaledBitmap, roundedCornerRect, roundedCornerRect, cornerPaint); return roundedCornerBitmap; }
From source file:Main.java
public static Bitmap roundCorners(Bitmap bitmap, float radius) { Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig()); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); canvas.drawARGB(0, 0, 0, 0);//from w w w . j a v a 2 s . c o m paint.setColor(color); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:Main.java
public static Bitmap changeBitmapColor(Bitmap bmp, int color) { Bitmap b = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig()); Canvas canvas = new Canvas(b); Paint paint = new Paint(); paint.setColor(color);/* w ww . ja v a2 s . c om*/ paint.setAntiAlias(true); canvas.drawBitmap(bmp, bmp.getWidth(), bmp.getHeight(), paint); return b; }
From source file:Main.java
static private Bitmap smallCoverPostProc(Bitmap smallBitmap) { try {//from w w w . j a va 2 s. c o m Bitmap smallBitmapPostProc = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), Bitmap.Config.RGB_565); Canvas canvas = new Canvas(); canvas.setBitmap(smallBitmapPostProc); Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bitmapToShade = Bitmap.createBitmap(smallBitmap, 2, 2, smallBitmap.getWidth() - 4, smallBitmap.getHeight() - 4); BitmapShader bmShader = new BitmapShader(bitmapToShade, TileMode.CLAMP, TileMode.CLAMP); paint.setShader(bmShader); canvas.drawRoundRect(new RectF(2, 2, smallBitmap.getWidth() - 2, smallBitmap.getHeight() - 2), 4, 4, paint); return smallBitmapPostProc; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE);/* w ww. j av a 2 s. co m*/ paint.setDither(false); Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Matrix m = new Matrix(); m.setScale(contour.getWidth() * 1.0f / background.getWidth(), contour.getHeight() * 1.0f / background.getHeight()); paint.setAlpha((int) (alpha * 0xff)); canvas.drawBitmap(background, m, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); paint.setAlpha(0xff); canvas.drawBitmap(contour, 0, 0, paint); return bitmap; }
From source file:Main.java
public static Bitmap roundCorners(final Bitmap source, final float radius) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE);/*from w w w.j av a 2 s . c o m*/ Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
From source file:Main.java
public static Bitmap circleBitmap(final Bitmap source) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE);// w w w.ja v a2 s . co m Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); final float radius = width > height ? height / 2 : width / 2; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
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 . java 2 s . c om*/ 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
public static Bitmap roundCorners(final Bitmap bitmap, final int radiusX, final int radiusY) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE);/*from w w w . j a va 2s . c o m*/ Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); canvas.drawRoundRect(new RectF(0, 0, width, height), radiusX, radiusY, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(bitmap, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); return rounded; }