do Trim on Bitmap - Android Graphics

Android examples for Graphics:Bitmap Crop

Description

do Trim on Bitmap

Demo Code


//package com.java2s;
import android.graphics.Bitmap;

import android.util.Log;

public class Main {
    private static final String TAG = "BitmapHelper";

    public static Bitmap doTrim(Bitmap b, int trimLeft, int trimRight,
            int trimTop, int trimBottom) {


        if (trimLeft < 0)
            trimLeft = 0;//from w ww . j a  v a 2  s. co m
        if (trimRight < 0)
            trimRight = 0;
        if (trimTop < 0)
            trimTop = 0;
        if (trimBottom < 0)
            trimBottom = 0;

        if (trimLeft + trimRight >= b.getWidth()
                || trimTop + trimBottom >= b.getHeight())
            return b;

        b = Bitmap.createBitmap(b, trimLeft, trimTop, b.getWidth()
                - trimRight - trimLeft, b.getHeight() - trimBottom
                - trimTop, null, true);

        return b;
    }
}

Related Tutorials