Android Bitmap Crop getTrimmedBottom(Bitmap img)

Here you can find the source of getTrimmedBottom(Bitmap img)

Description

returns blank area of the image to the downward direction of the image

Parameter

Parameter Description
img a parameter

Return

blank area of the image to the downward direction of the image

Declaration

public static int getTrimmedBottom(Bitmap img) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    /**// w w  w  . j  a v a2  s. c om
     * returns blank area of the image to the downward direction of the image
     * @param img
     * @return blank area of the image to the downward direction of the image
     */
    public static int getTrimmedBottom(Bitmap img) {
        int width = img.getWidth();
        int height = img.getHeight();
        int data = 0;

        for (int i = 0; i < width; ++i) {
            for (int j = height - 1; j >= 0; --j) {
                if (img.getPixel(i, j) != Color.TRANSPARENT && j > data) {
                    data = j;
                    break;
                }
            }
        }

        return data;
    }

    /**
     * returns blank area of the image to the downward direction of the image
     * @param img
     * @param border
     * @return blank area of the image to the downward direction of the image
     */
    public static int getTrimmedBottom(Bitmap img, int border) {
        int width = img.getWidth();
        int height = img.getHeight();
        int data = 0;

        for (int i = 0; i < width; ++i) {
            for (int j = height - 1; j >= 0; --j) {
                if (img.getPixel(i, j) != Color.TRANSPARENT && j > data) {
                    data = j;
                    break;
                }
            }
        }

        return data + border;
    }
}

Related

  1. createCenterCropBitmap(Bitmap srcBitmap, int dstWidth, int dstHeight, boolean tryRecycleSource)
  2. crop(Bitmap bitmap, float newWidth, float newHeight)
  3. crop(Bitmap bitmap, int x, int y, float newWidth, float newHeight)
  4. cropBitmapToSquare(Bitmap bitmap, int squareLength)
  5. cropBitmapToSquare(String bitmapPath, int squareLength)
  6. getTrimmedBottom(Bitmap img, int border)
  7. getTrimmedLeft(Bitmap img)
  8. getTrimmedLeft(Bitmap img, int border)
  9. getTrimmedRight(Bitmap img)