Android Bitmap Crop getTrimmedTop(Bitmap img, int border)

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

Description

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

Parameter

Parameter Description
img a parameter
border a parameter

Return

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

Declaration

public static int getTrimmedTop(Bitmap img, int border) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

public class Main {
    /**//from ww w  .  j  a  v  a  2  s. c  om
     * 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. getTrimmedLeft(Bitmap img)
  2. getTrimmedLeft(Bitmap img, int border)
  3. getTrimmedRight(Bitmap img)
  4. getTrimmedRight(Bitmap img, int border)
  5. getTrimmedTop(Bitmap img)
  6. cutImg(File file, int newWidth, int newHeight)
  7. cutStretchImage(Bitmap image, int xsize, int ysize)
  8. cutImg(Bitmap bitmap, int newWidth, int newHeight)
  9. cropCenter(Bitmap bitmap, boolean recycle)