create Round Image - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

create Round Image

Demo Code

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class Main {

  public static Bitmap createRoundImage(String colour, int bitmapW, int bitmapH) {
    return createRoundImage(Color.parseColor(colour), bitmapW, bitmapH);
  }/*w w  w  . ja va2s. co m*/

  public static Bitmap createRoundImage(int colour, int bitmapW, int bitmapH) {
    Bitmap circleBitmap = Bitmap.createBitmap(bitmapW, bitmapH, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(circleBitmap);

    Paint p = new Paint();
    p.setAntiAlias(true);
    p.setStrokeWidth(5);
    p.setColor(colour);
    c.drawCircle(circleBitmap.getWidth() - bitmapW / 2, circleBitmap.getHeight() - bitmapH / 2, bitmapW / 2, p);
    return circleBitmap;
  }

}

Related Tutorials