Java ByteBuffer Size overlapsPoints(BufferedImage inImage, int inX, int inY, int inWidth, int inHeight, Color inTextColour)

Here you can find the source of overlapsPoints(BufferedImage inImage, int inX, int inY, int inWidth, int inHeight, Color inTextColour)

Description

Tests whether there are any dark pixels in the image within the specified x,y rectangle

License

Open Source License

Parameter

Parameter Description
inImage image to test
inX left X coordinate
inY bottom Y coordinate
inWidth width of rectangle
inHeight height of rectangle
inTextColour colour of text

Return

true if the rectangle overlaps stuff too close to the given colour

Declaration

public static boolean overlapsPoints(BufferedImage inImage, int inX, int inY, int inWidth, int inHeight,
        Color inTextColour) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;
import java.awt.image.BufferedImage;

public class Main {
    /**/*from ww w  .  j a v  a 2s .c  o  m*/
     * Tests whether there are any dark pixels in the image within the specified x,y rectangle
     * @param inImage image to test
     * @param inX left X coordinate
     * @param inY bottom Y coordinate
     * @param inWidth width of rectangle
     * @param inHeight height of rectangle
     * @param inTextColour colour of text
     * @return true if the rectangle overlaps stuff too close to the given colour
     */
    public static boolean overlapsPoints(BufferedImage inImage, int inX, int inY, int inWidth, int inHeight,
            Color inTextColour) {
        // each of the colour channels must be further away than this to count as empty
        final int BRIGHTNESS_LIMIT = 80;
        final int textRGB = inTextColour.getRGB();
        final int textLow = textRGB & 255;
        final int textMid = (textRGB >> 8) & 255;
        final int textHigh = (textRGB >> 16) & 255;
        try {
            // loop over x coordinate of rectangle
            for (int x = 0; x < inWidth; x++) {
                // loop over y coordinate of rectangle
                for (int y = 0; y < inHeight; y++) {
                    int pixelColor = inImage.getRGB(inX + x, inY - y);
                    // split into four components rgba
                    int pixLow = pixelColor & 255;
                    int pixMid = (pixelColor >> 8) & 255;
                    int pixHigh = (pixelColor >> 16) & 255;
                    //int fourthBit = (pixelColor >> 24) & 255; // alpha ignored
                    // If colours are too close in any channel then it's an overlap
                    if (Math.abs(pixLow - textLow) < BRIGHTNESS_LIMIT
                            || Math.abs(pixMid - textMid) < BRIGHTNESS_LIMIT
                            || Math.abs(pixHigh - textHigh) < BRIGHTNESS_LIMIT) {
                        return true;
                    }
                }
            }
        } catch (NullPointerException e) {
            // ignore null pointers, just return false
        }
        return false;
    }
}

Related

  1. markDifferencesWithAMarker(final BufferedImage image, final Point[] pixels, final int markingSizeX, final int markingSizeY)
  2. markDifferencesWithBoxes(final BufferedImage image, final Point[] pixels, final int markingSizeX, final int markingSizeY)
  3. maybeGrow(List l, int size)
  4. needsThumbnail(BufferedImage image, int newSize)
  5. newArgbBufferedImage(int width, int height)
  6. pack(List buffers, int elements, int size)
  7. rescaleImage(BufferedImage img, int targetWidth, int targetHeight, Object hint)
  8. rightSize(ByteBuffer in)
  9. sameSize(BufferedImage im1, BufferedImage im2)