Android Bitmap Scale scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth)

Here you can find the source of scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth)

Description

scale Clip Bitmap By Circle

Declaration

public static Bitmap scaleClipBitmapByCircle(Bitmap src, int nRadius,
            float fStrokeWidth) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Canvas;
import android.graphics.Color;

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

public class Main {
    public static Bitmap scaleClipBitmapByCircle(Bitmap src, int nRadius,
            float fStrokeWidth) {
        if (null != src) {
            Bitmap maskMap = Bitmap.createBitmap(nRadius << 1,
                    nRadius << 1, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(maskMap);
            canvas.drawARGB(0, 0, 0, 0);
            Paint ptDrawCircle = new Paint();
            ptDrawCircle.setColor(Color.BLACK);
            ptDrawCircle.setStyle(Style.FILL);
            canvas.drawCircle(nRadius, nRadius, nRadius, ptDrawCircle);
            Paint paint = new Paint();
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
            Rect rcSrc = new Rect();
            rcSrc.set(0, 0, src.getWidth(), src.getHeight());
            Rect rcDst = new Rect();
            rcDst.set(0, 0, maskMap.getWidth(), maskMap.getHeight());
            canvas.drawBitmap(src, rcSrc, rcDst, paint);
            ptDrawCircle.setStyle(Style.STROKE);
            ptDrawCircle.setStrokeWidth(fStrokeWidth);
            ptDrawCircle.setColor(Color.WHITE);
            ptDrawCircle.setAntiAlias(true);
            canvas.drawCircle(nRadius, nRadius, nRadius - fStrokeWidth / 2,
                    ptDrawCircle);//  ww  w  .  j  ava 2 s. c o m
            return maskMap;
        }
        return null;
    }
}

Related

  1. generateScaledBitmap(Drawable drawable, int width, int height)
  2. generateScaledBitmap(byte[] bitMapData, int width, int height)
  3. crossStretchImageX(Bitmap image, int xsize)
  4. scaleBitmap(Bitmap bitmap, int width, int height)
  5. scaleBitmap(String path, int newWidth, int newHeight)
  6. getScaledImageFromUri(Activity activity, Uri uri, int size)
  7. imageScale(Bitmap bitmap, int dst_w, int dst_h)
  8. scaleBitmap(Bitmap bitmap, float scale)
  9. scaleBitmapDown(Bitmap bitmap)