Java BufferedImage Operation findLegendLH(BufferedImage bufferedImage)

Here you can find the source of findLegendLH(BufferedImage bufferedImage)

Description

This find the low and high pixels with the legend (assuming the legend is near the bottom and is along the left edge, and spans the width of the image).

License

Open Source License

Return

the low (a smaller number) and high y (a bigger number) of the legend. They are the y's of the edges. If trouble, this returns {0, 0}.

Declaration

public static int[] findLegendLH(BufferedImage bufferedImage) 

Method Source Code

//package com.java2s;
/* /*from   www .ja v a2  s .co  m*/
 * SgtUtil Copyright 2005, NOAA.
 * See the LICENSE.txt file in this file's directory.
 */

import java.awt.image.BufferedImage;

public class Main {
    /** This find the low and high pixels with the legend
     * (assuming the legend is near the bottom and is along the left edge,
     * and spans the width of the image).
     *
     * @return the low (a smaller number) and high y (a bigger number) of the legend.
     *   They are the y's of the edges.
     *   If trouble, this returns {0, 0}.
     */
    public static int[] findLegendLH(BufferedImage bufferedImage) {
        int black = 0xFF000000;
        int height = bufferedImage.getHeight();
        int lh[] = new int[] { 0, 0 };

        //find bottom edge
        for (int y = height - 1; y >= 0; y--) {
            if (bufferedImage.getRGB(0, y) == black) {
                lh[1] = y;
                break;
            }
        }

        //find top edge
        for (int y = lh[1] - 1; y >= 0; y--) {
            if (bufferedImage.getRGB(0, y) != black) {
                lh[0] = y + 1;
                break;
            }
        }
        //String2.log("findLegendLH low=" + lh[0] + " high=" + lh[1]);
        return lh;
    }
}

Related

  1. findavg(BufferedImage bimg)
  2. findColor(BufferedImage image, int startX, int startY, int dirX, int dirY, int colorIndex)
  3. findDifference(BufferedImage img2, BufferedImage img1)
  4. findDominantColor(BufferedImage paramBufferedImage)
  5. findLegacyColorModel(BufferedImage image)
  6. findTranslation(AffineTransform at, BufferedImage bi)
  7. fixImage(BufferedImage img, String ext)
  8. floatBufferToGrayBufferedImage(FloatBuffer floatBuffer, BufferedImage bi)
  9. floodFill(BufferedImage img, int startX, int startY, Color targetColor, Color replacementColor)