Java BufferedImage Transparent bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)

Here you can find the source of bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)

Description

Returns whether the given pixel is bordered by any non-transparent pixel.

License

Open Source License

Declaration

protected static boolean bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced,
        int x, int y) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

import java.awt.image.BufferedImage;

public class Main {
    /** Used when seeking fully transparent pixels for outlining. */
    protected static final int TRANS_MASK = (0xFF << 24);

    /**/*from   w w w  .j  a  va 2  s. c o  m*/
     * Returns whether the given pixel is bordered by any non-transparent
     * pixel.
     */
    protected static boolean bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced,
            int x, int y) {
        // check the three-pixel row above the pixel
        if (y > 0) {
            for (int rxx = x - 1; rxx <= x + 1; rxx++) {
                if (rxx < 0 || rxx >= wid || traced[((y - 1) * wid) + rxx]) {
                    continue;
                }

                if ((data.getRGB(rxx, y - 1) & TRANS_MASK) != 0) {
                    return true;
                }
            }
        }

        // check the pixel to the left
        if (x > 0 && !traced[(y * wid) + (x - 1)]) {
            if ((data.getRGB(x - 1, y) & TRANS_MASK) != 0) {
                return true;
            }
        }

        // check the pixel to the right
        if (x < wid - 1 && !traced[(y * wid) + (x + 1)]) {
            if ((data.getRGB(x + 1, y) & TRANS_MASK) != 0) {
                return true;
            }
        }

        // check the three-pixel row below the pixel
        if (y < hei - 1) {
            for (int rxx = x - 1; rxx <= x + 1; rxx++) {
                if (rxx < 0 || rxx >= wid || traced[((y + 1) * wid) + rxx]) {
                    continue;
                }

                if ((data.getRGB(rxx, y + 1) & TRANS_MASK) != 0) {
                    return true;
                }
            }
        }

        return false;
    }
}

Related

  1. ApplyTransparency(BufferedImage image, Image mask)
  2. applyTransparency(BufferedImage src, float alpha)
  3. ConvToTransparentImage(BufferedImage src, float alpha)
  4. cutTransparentBorder(BufferedImage src)
  5. fixTransparency(String var0, BufferedImage var1)
  6. makeTransparency(BufferedImage image, int color)