Android Bitmap Crop getCroppedBitmap(Bitmap bitmap)

Here you can find the source of getCroppedBitmap(Bitmap bitmap)

Description

get Cropped Bitmap

Declaration

public static Bitmap getCroppedBitmap(Bitmap bitmap) 

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.PorterDuff;

import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;

public class Main {
    public static Bitmap getCroppedBitmap(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(),
                bitmap.getHeight());/*  w  ww  .  j  a va 2  s. co  m*/

        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        paint.setDither(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.parseColor("#BAB399"));
        canvas.drawCircle(bitmap.getWidth() / 2 + 0.7f,
                bitmap.getHeight() / 2 + 0.7f,
                bitmap.getWidth() / 2 + 0.1f, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;
    }
}

Related

  1. cropCenterBitmap(Bitmap bitmap, int newWidth, int newHeight)
  2. resizeDownAndCropCenter(Bitmap bitmap, int size, boolean recycle)
  3. resizeDownIfTooBig(Bitmap bitmap, int targetSize, boolean recycle)
  4. resizeDownToPixels(Bitmap bitmap, int targetPixels, boolean recycle)
  5. cropImage(Context context, Uri imageuri, Uri tempUri)