List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:Main.java
public static Bitmap getRoundAngleImage(Bitmap bitmap, int pixels, boolean recycleOld) { Bitmap output = null;//from www. ja v a2s. c o m if (bitmap != null && !bitmap.isRecycled()) { 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); paint.setFilterBitmap(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(bitmap, rect, rect, paint); if (recycleOld) bitmap.recycle(); return output; } return output; }
From source file:Main.java
public static Bitmap createRoundCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap roundCornerBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);/* ww w. j a v a2 s .c om*/ Canvas canvas = new Canvas(roundCornerBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); RectF rectF = new RectF(rect); int color = 0xff424242; paint.setAntiAlias(true); 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 roundCornerBitmap; }
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 = bitmap.getWidth() / 2; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);//from w w w. j av a 2s . co m 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:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java
@Nullable public static Drawable getDefaultImage(@NonNull Context context, @DrawableRes int res) { try {// w w w .ja v a 2 s .com int color = ColorHelper.getAttributeColor(context, android.R.attr.textColorSecondary); int padding = context.getResources().getDimensionPixelSize(R.dimen.default_image_padding); Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res); drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); } Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); Bitmap tintedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() + padding, Bitmap.Config.ARGB_8888); Canvas tintedCanvas = new Canvas(tintedBitmap); int background = ColorHelper.getAttributeColor(context, R.attr.card_background); Paint paint = new Paint(); paint.setFilterBitmap(true); paint.setAntiAlias(true); tintedCanvas.drawColor(background, PorterDuff.Mode.ADD); tintedCanvas.drawBitmap(bitmap, (tintedCanvas.getWidth() - bitmap.getWidth()) / 2, (tintedCanvas.getHeight() - bitmap.getHeight()) / 2, paint); return new BitmapDrawable(context.getResources(), tintedBitmap); } catch (Exception | OutOfMemoryError e) { return null; } }
From source file:Main.java
/** * This method is used to create bitmap with rounded corners. * //from w ww . j av a2 s . c o m * @param bitmap * which is to be rouded. * @param pixels * dimension of the resultant image * @return new bitmap with the specified dimension */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { 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 = pixels; paint.setAntiAlias(true); 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 getRoundedCornerBitmap(Context context, Bitmap bitmap, int color) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); color = 0xff424242; // FIXME 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 = convertDipsToPixels(context, ROUND_DIPS); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);/* w ww .j a v a2 s .c o m*/ 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 getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels) { maxHeight = (int) (getApplicationContext().getResources().getDisplayMetrics().density * maxHeight); float scale = bitmap.getHeight() * 1.0f / maxHeight; int newWidth = (int) (bitmap.getWidth() / scale); Bitmap output = Bitmap.createBitmap(newWidth, maxHeight, Bitmap.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 Rect dstRect = new Rect(0, 0, newWidth, maxHeight); final RectF rectF = new RectF(dstRect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);/*from www .j ava2 s . co m*/ paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, dstRect, paint); return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { if (bitmap == null) return null; Bitmap output;/*from w w w .j a va 2s . c om*/ try { 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); 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); } catch (Exception ex) { //adding as a precaution because finding a few crashes in bitmap modification return bitmap; } return output; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels) { if (bitmap == null) return bitmap; maxHeight = (int) (getApplicationContext().getResources().getDisplayMetrics().density * maxHeight); float scale = bitmap.getHeight() * 1.0f / maxHeight; int newWidth = (int) (bitmap.getWidth() / scale); Bitmap output = Bitmap.createBitmap(newWidth, maxHeight, Bitmap.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 Rect dstRect = new Rect(0, 0, newWidth, maxHeight); final RectF rectF = new RectF(dstRect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);//from ww w .j av a2 s.co m paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, dstRect, paint); return output; }
From source file:Main.java
public static Bitmap createRoundCornerBitmap(Bitmap bitmap, float roundPx, boolean lt, boolean rt, boolean lb, boolean rb) { Bitmap roundCornerBitmap = createRoundCornerBitmap(bitmap, roundPx); Canvas canvas = new Canvas(roundCornerBitmap); canvas.drawARGB(0, 0, 0, 0);/*from w ww .j a va2 s . c o m*/ int bw = bitmap.getWidth(); int bh = bitmap.getHeight(); int centerW = bw / 2; int centerH = bh / 2; Paint paint = new Paint(); Paint defaultPaint = new Paint(); int color = 0xff424242; paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); paint.setAntiAlias(true); paint.setColor(color); Bitmap cutBitmap = null; Canvas cutCanvas = null; if (!lt) { cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888); cutCanvas = new Canvas(cutBitmap); cutCanvas.drawRect(0, 0, centerW, centerH, defaultPaint); cutCanvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint); cutBitmap.recycle(); } if (!rt) { cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888); cutCanvas = new Canvas(cutBitmap); cutCanvas.drawRect(centerW, 0, bw, centerH, defaultPaint); cutCanvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint); cutBitmap.recycle(); } if (!lb) { cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888); cutCanvas = new Canvas(cutBitmap); cutCanvas.drawRect(0, centerH, centerW, bh, defaultPaint); cutCanvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint); cutBitmap.recycle(); } if (!rb) { cutBitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ARGB_8888); cutCanvas = new Canvas(cutBitmap); cutCanvas.drawRect(centerW, centerH, bw, bh, defaultPaint); cutCanvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawBitmap(cutBitmap, 0, 0, defaultPaint); cutBitmap.recycle(); } return roundCornerBitmap; }