Android examples for Graphics:Bitmap Rounded
Radius Image
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.PorterDuff.Mode; public class Main { public synchronized static Bitmap RadiusImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int size = Math.min(width, height); Bitmap clipArea = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(clipArea); c.drawRoundRect(new RectF(0, 0, size, size), size / 10, size / 10, new Paint(Paint.ANTI_ALIAS_FLAG)); Bitmap newImage = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(newImage); Paint paint = new Paint(); canvas.drawBitmap(clipArea, 0, 0, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bm, new Rect(0, 0, size, size), new Rect(0, 0, size, size), paint);// w w w . j a va 2s . c o m bm.recycle(); return newImage; } }