get BufferedImage Split RGB - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

get BufferedImage Split RGB

Demo Code


//package com.java2s;

import java.awt.image.BufferedImage;

public class Main {

    public static int[] getSplitRGB(BufferedImage image, int x, int y) {
        int[] rgb = null;
        if (image != null && x < image.getWidth() && y < image.getHeight()) {
            rgb = new int[3];
            int pixel = image.getRGB(x, y);
            rgb = getSplitRGB(pixel);/*from w  w  w  .  j ava 2  s  . c o m*/
        }
        return rgb;
    }

    public static int[] getSplitRGB(int pixel) {
        int[] rgbs = new int[3];
        rgbs[0] = (pixel & 0xff0000) >> 16;
        rgbs[1] = (pixel & 0xff00) >> 8;
        rgbs[2] = (pixel & 0xff);
        return rgbs;
    }
}

Related Tutorials