Android Bitmap Crop getTrimmedRight(Bitmap img)

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

Description

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

Parameter

Parameter Description
img a parameter

Return

blank area of the image to the right direction of the image

Declaration

public static int getTrimmedRight(Bitmap img) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Color;

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

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

        return data;
    }

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

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

        return data + border;
    }
}

Related

  1. cropBitmapToSquare(String bitmapPath, int squareLength)
  2. getTrimmedBottom(Bitmap img)
  3. getTrimmedBottom(Bitmap img, int border)
  4. getTrimmedLeft(Bitmap img)
  5. getTrimmedLeft(Bitmap img, int border)
  6. getTrimmedRight(Bitmap img, int border)
  7. getTrimmedTop(Bitmap img)
  8. getTrimmedTop(Bitmap img, int border)
  9. cutImg(File file, int newWidth, int newHeight)