Android Bitmap Corner Round getRoundedRectBitmap(Bitmap bitmap, int pixels)

Here you can find the source of getRoundedRectBitmap(Bitmap bitmap, int pixels)

Description

get Rounded Rect Bitmap

Declaration

public static Bitmap getRoundedRectBitmap(Bitmap bitmap, int pixels) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;

public class Main {
    public static Bitmap getRoundedRectBitmap(Bitmap bitmap, int pixels) {
        Bitmap result = null;/*from   ww w.  ja  va 2  s.com*/
        try {
            result = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(result);

            int color = 0xFF33B5E5;
            Paint paint = new Paint();
            Rect rect = new Rect(0, 0, 98, 98);

            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.FILL);
            canvas.drawARGB(0, 0, 0, 0);
            paint.setColor(color);
            canvas.drawCircle(50, 50, 50, paint);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
            canvas.drawBitmap(bitmap, rect, rect, paint);

        } catch (NullPointerException e) {
        } catch (OutOfMemoryError o) {
        }
        return result;
    }
}

Related

  1. getRoundBitmapFromUrl(String url, int pixels)
  2. toRoundCorner(Bitmap bitmap, int pixels)
  3. toRoundCorner( BitmapDrawable bitmapDrawable, int pixels)
  4. getRoundedCornerBitmap(Bitmap bitmap, float roundPx)
  5. getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels)
  6. toRoundBitmap(Bitmap bitmap)
  7. toRoundBitmap(Bitmap bitmap)
  8. getCircleBitmap(Uri uri, Context context)