get Subimage Bitmap by Rect - Android Graphics

Android examples for Graphics:Bitmap Crop

Description

get Subimage Bitmap by Rect

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

public class Main {
    public static Bitmap getSubimage(Bitmap b, Rect copyRect) {
        // Extracts a part of a Bitmap defined by copyRect.
        Bitmap subImage = Bitmap.createBitmap(copyRect.width(),
                copyRect.height(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(subImage);
        c.drawBitmap(b, copyRect,//from   w w w . j a va  2  s. c o m
                new Rect(0, 0, copyRect.width(), copyRect.height()), null);
        return subImage;
    }
}

Related Tutorials