The image cut circular

Acquired bitmap circular shear


private Bitmap createCircleBitmap(Bitmap resource)
    {
        // Get the image width
        int width = resource.getWidth();
        Paint paint = new Paint();
        // set Anti-Aliasing
        paint.setAntiAlias(true);

        // create a bitmap with the original bitmap as the width of the square
        Bitmap circleBitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
        // the bitmap to create a low-canvas
        Canvas canvas = new Canvas(circleBitmap);
        // to (width / 2, width / 2) as the center, width / 2 is the radius of a circle
        canvas.drawCircle(width/2, width/2, width/2, paint);

        // set the pen is intersected mode
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        // crop the picture
        canvas.drawBitmap(resource, 0, 0, paint);

        return circleBitmap;
    }

  

Guess you like

Origin www.cnblogs.com/wang-jingyuan/p/12174066.html
cut