is White Pixel in BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

is White Pixel in BufferedImage

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {
    public static boolean isWhitePixel(BufferedImage i, int x, int y) {
        if (x < 0) {
            return false;
        }/*ww w  .  j a v a  2s  . c  o m*/
        if (y < 0) {
            return false;
        }

        if (x >= i.getWidth()) {
            return false;
        }

        if (y >= i.getHeight()) {
            return false;
        }

        return ((short) i.getRGB(x, y) != 0);
    }

    public static int[] getRGB(BufferedImage i, int x, int y) {
        int rgb = i.getRGB(x, y);

        int[] res = new int[3];
        res[0] = (rgb >> 16) & 255;
        res[1] = (rgb >> 8) & 255;
        res[2] = (rgb) & 255;
        return res;
    }
}

Related Tutorials