List of usage examples for android.graphics Paint setAntiAlias
public void setAntiAlias(boolean aa)
From source file:Main.java
/** * Create a bitmap which is wrapped to circle * (similar to what you can see in G+ profile pic.) * * @param bitmap Original Bitmap/* ww w .j a v a 2 s . c o m*/ * @return Circled bitmap */ public static Bitmap createCircleBitmap(Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint bitmapPaint = new Paint(); bitmapPaint.setAntiAlias(true); bitmapPaint.setShader(bitmapShader); Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawCircle(width / 2, height / 2, Math.min(width, height) / 2, bitmapPaint); return output; }
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER);/*from ww w. j a va2s . c om*/ paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); BitmapDrawable bitmapDrawable = new BitmapDrawable(res, buffer); bitmapDrawable.setTargetDensity(canvas); return bitmapDrawable; }
From source file:Main.java
public static Bitmap createCircleBitmap(Bitmap bitmap) { if (bitmap == null) { return null; }/* www .j a v a 2 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 addLabelToBitmap(Bitmap src, String label) { float densityFactor = Resources.getSystem().getDisplayMetrics().density; final float textPadding = src.getWidth() * 0.05f; Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint textPaint = new Paint(); textPaint.setAntiAlias(true); textPaint.setTextSize(12 * densityFactor); textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(2 * densityFactor); textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK); float textWidth = textPaint.measureText(label); float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth; canvas.drawBitmap(src, 0, 0, textPaint); canvas.save();//from ww w . j a v a 2 s . c o m canvas.scale(scaleFactor, scaleFactor); float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2; float textPosY = (src.getHeight() - textPadding) / scaleFactor; canvas.drawText(label, textPosX, textPosY, textPaint); canvas.restore(); return result; }
From source file:Main.java
/** * clip source bitmap into a circle bitmap * * @param src the source bitmap/*from w ww .ja v a 2 s .c om*/ * @param recycle whether recycle the source bitmap * @param config bitmap config * @return clipped circle bitmap */ public static Bitmap createCircleBitmap(Bitmap src, boolean recycle, Bitmap.Config config) { if (src == null) { return null; } if (config == null) { config = Bitmap.Config.ARGB_8888; } Bitmap out = Bitmap.createBitmap(src.getWidth(), src.getHeight(), config); final Rect rect = new Rect(0, 0, Math.min(src.getWidth(), src.getHeight()), Math.min(src.getWidth(), src.getHeight())); Paint paint = new Paint(); paint.setAntiAlias(true); Canvas canvas = new Canvas(out); canvas.drawARGB(0, 0, 0, 0); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); if (recycle) { src.recycle(); } return out; }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int backgroundColor, int borderColor) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth() + 12, bitmap.getHeight() + 12, Bitmap.Config.ARGB_8888);/*from w ww . j a v a 2 s .c om*/ Canvas canvas = new Canvas(output); //canvas.drawARGB(Color.alpha(backgroundColor), Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor)); Paint borderPaint = new Paint(); borderPaint.setAntiAlias(true); borderPaint.setColor(borderColor); borderPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); borderPaint.setShadowLayer(2.0f, 0.0f, 2.0f, Color.BLACK); int centerWidth = output.getWidth() / 2; int centerHeight = output.getHeight() / 2; canvas.drawCircle(centerWidth, centerHeight, ((centerWidth + centerHeight) / 2) - 4, borderPaint); Paint paint = new Paint(); paint.setAntiAlias(true); Rect rectS = new Rect(0, 0, output.getWidth() - 12, output.getHeight() - 12); Rect rectD = new Rect(0, 0, output.getWidth(), output.getHeight()); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(bitmap, rectS, rectD, paint); return output; }
From source file:Main.java
public static Bitmap getPlusBitmap(Context context, String s) { Paint paint = new Paint(); paint.setAntiAlias(true); Bitmap bitmap = BitmapFactory.decodeStream(getCommunityPicInputStream(s)); Bitmap bitmap1;//from w ww .java 2 s.com if (bitmap != null) { Bitmap bitmap2 = BitmapFactory.decodeResource(context.getResources(), 0x7f02003f); bitmap1 = Bitmap.createBitmap(bitmap.getWidth() + bitmap2.getWidth() / 2, bitmap.getHeight() + bitmap2.getHeight() / 2, android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap1); canvas.drawARGB(0, 0, 0, 0); canvas.drawBitmap(bitmap, 0.0F, 0.0F, paint); bitmap.recycle(); canvas.drawBitmap(bitmap2, bitmap.getWidth() - bitmap2.getWidth() / 2, bitmap.getHeight() - bitmap2.getHeight() / 2, paint); bitmap2.recycle(); } else { bitmap1 = null; } return bitmap1; }
From source file:Main.java
public static void drawBackground(Canvas canvas, int backgroundColor, int width, int height) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setColor(backgroundColor);/*from w w w. ja va2 s .co m*/ canvas.drawRect(0, 0, width, height, paint); }
From source file:Main.java
/** * Returns a rounded bitmap using specified bitmap image. * /* ww w.ja v a2 s .c om*/ * @param scaleBitmapImage bitmap to make round image. * @return rounded bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) { if (scaleBitmapImage == null) return null; int targetWidth = (int) DP; int targetHeight = (int) DP; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); Paint p = new Paint(); p.setAntiAlias(true); canvas.clipPath(path); canvas.drawBitmap(scaleBitmapImage, new Rect(0, 0, scaleBitmapImage.getWidth(), scaleBitmapImage.getHeight()), new Rect(0, 0, targetWidth, targetHeight), p); p.setARGB(255, 16, 18, 16); scaleBitmapImage.recycle(); return targetBitmap; }
From source file:Main.java
public static Bitmap getRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap out = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(out); Paint paint = new Paint(); paint.setColor(Color.WHITE);//from w w w . j a va 2s .c om paint.setAntiAlias(true); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); Rect rect = new Rect(0, 0, width, height); canvas.drawBitmap(bitmap, rect, rect, paint); return out; }