List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:com.almalence.googsharing.Thumbnail.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int size, int pixels) { final int side = Math.min(bitmap.getWidth(), bitmap.getHeight()); final Bitmap bitmapCropped = Bitmap.createBitmap(bitmap, (bitmap.getWidth() - side) / 2, (bitmap.getHeight() - side) / 2, side, side); final Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rectSrc = new Rect(0, 0, bitmapCropped.getWidth(), bitmapCropped.getHeight()); final Rect rect = new Rect(6, 6, output.getWidth() - 6, output.getHeight() - 6); final RectF rectF = new RectF(rect); final RectF rectFBorder = new RectF(0, 0, output.getWidth(), output.getHeight()); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);//from w ww. j av a2 s . c om paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmapCropped, rectSrc, rect, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP)); canvas.drawRoundRect(rectFBorder, roundPx, roundPx, paint); return output; }
From source file:com.c4mprod.utils.ImageManager.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 = 20; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0);/* ww w .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); if (output != bitmap) { bitmap.recycle(); } return output; }
From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java
public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) { boolean isLandscape = bitmap.getWidth() > bitmap.getHeight(); int newWidth, newHeight; if (isLandscape) { newWidth = maxSize;/* ww w .jav a 2 s . c om*/ newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight()); } else { newHeight = maxSize; newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth()); } Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); if (resizedBitmap != bitmap) bitmap.recycle(); Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(), Config.ARGB_8888); Canvas roundedCanvas = new Canvas(roundedProfile); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = 7.0f; paint.setAntiAlias(true); roundedCanvas.drawARGB(0, 0, 0, 0); paint.setColor(color); roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint); return roundedProfile; }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private 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);/*ww w. j av a 2 s. 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.bamobile.fdtks.util.Tools.java
public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, int borderWidth) { if (bitmap == null || bitmap.isRecycled()) { return null; }/* w w w . j ava2s .c om*/ final int width = bitmap.getWidth() + borderWidth; final int height = bitmap.getHeight() + borderWidth; Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); Canvas canvas = new Canvas(canvasBitmap); float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setShader(null); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLUE); paint.setStrokeWidth(borderWidth); canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint); return canvasBitmap; }
From source file:com.snowpuppet.alert.formclock.FormClockView.java
private void updatePaints() { FormClockRenderer.ClockPaints paints = new FormClockRenderer.ClockPaints(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(mColor1);/*from w w w . j av a 2 s . c om*/ paints.fills[0] = paint; paint = new Paint(paint); paint.setColor(mColor2); paints.fills[1] = paint; paint = new Paint(paint); paint.setColor(mColor3); paints.fills[2] = paint; mHourMinRenderer.setPaints(paints); mSecondsRenderer.setPaints(paints); invalidate(); }
From source file:pl.mg6.newmaps.demo.MarkersExampleActivity.java
private Bitmap prepareBitmap() { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_left); bitmap = bitmap.copy(Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE);/*from w ww. j a va 2 s .c o m*/ paint.setTextAlign(Align.CENTER); paint.setTextSize(getResources().getDimension(R.dimen.text_size)); String text = "mg6"; Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2.0f; float y = (bitmap.getHeight() - bounds.height()) / 2.0f - bounds.top; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static void setBackground(View v, Bitmap bm) { if (bm == null) { v.setBackgroundResource(0);/*from w w w . ja va2s.c o m*/ return; } int vwidth = v.getWidth(); int vheight = v.getHeight(); int bwidth = bm.getWidth(); int bheight = bm.getHeight(); float scalex = (float) vwidth / bwidth; float scaley = (float) vheight / bheight; float scale = Math.max(scalex, scaley) * 1.3f; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config); Canvas c = new Canvas(bg); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); ColorMatrix greymatrix = new ColorMatrix(); greymatrix.setSaturation(0); ColorMatrix darkmatrix = new ColorMatrix(); darkmatrix.setScale(.3f, .3f, .3f, 1.0f); greymatrix.postConcat(darkmatrix); ColorFilter filter = new ColorMatrixColorFilter(greymatrix); paint.setColorFilter(filter); Matrix matrix = new Matrix(); matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin matrix.postRotate(10); matrix.postScale(scale, scale); matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center c.drawBitmap(bm, matrix, paint); v.setBackgroundDrawable(new BitmapDrawable(bg)); }
From source file:com.liferay.mobile.screens.viewsets.defaultviews.userportrait.UserPortraitView.java
protected Paint getPaint(Bitmap bitmap) { BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader);/*from w ww . j a v a 2 s . c o m*/ return paint; }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private 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);//ww w . j a v a 2 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; }