Android Bitmap Crop getTrimmedTop(Bitmap img)

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

Description

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

Parameter

Parameter Description
img a parameter

Return

blank area of the image to the up direction of the image

Declaration

public static int getTrimmedTop(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  a  2 s. c o  m*/
     * returns blank area of the image to the up direction of the image
     * @param img
     * @return blank area of the image to the up direction of the image
     */
    public static int getTrimmedTop(Bitmap img) {
        int width = img.getWidth();
        int height = img.getHeight();
        int data = height;

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

        return data;
    }

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

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

        return data + border;
    }
}

Related

  1. getTrimmedBottom(Bitmap img, int border)
  2. getTrimmedLeft(Bitmap img)
  3. getTrimmedLeft(Bitmap img, int border)
  4. getTrimmedRight(Bitmap img)
  5. getTrimmedRight(Bitmap img, int border)
  6. getTrimmedTop(Bitmap img, int border)
  7. cutImg(File file, int newWidth, int newHeight)
  8. cutStretchImage(Bitmap image, int xsize, int ysize)
  9. cutImg(Bitmap bitmap, int newWidth, int newHeight)