Return to Snippet

Revision: 80874
at April 5, 2020 16:24 by m3000


Updated Title
Make circular bitmap

Updated URL


Updated Tags
android

Updated Description
this is the code to make the circular bitmap which is used in the image views of android.
at the end of the code the circle mode of bitmap is created by the enum mode.

Revision: 72507
at September 5, 2017 16:23 by m3000


Initial Code
private Bitmap getCircleBitmap(Bitmap bitmap) {
        final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(output);

        final int color = Color.RED;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawOval(rectF, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        bitmap.recycle();

        return output;
    }

Initial URL


Initial Description
this is the code to make the circular bitmap and use it in the image views and other viewers in android technology.
at the end of the code the circle mode of bitmap is created by the en um Mode.

Initial Title
Make circuar bitmap

Initial Tags


Initial Language
Java