return the red component of the pixel of the image - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Pixel

Description

return the red component of the pixel of the image

Demo Code


import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.log4j.Logger;

public class Main{
    /**//ww  w. j  av a2s. co m
     * return the red component of the pixel of the image
     * 
     * @param pixel
     *            the pixel number
     * @param colorModel
     * @return
     */
    public static int getRedRaw(final int pixel, final ColorModel colorModel) {
        return colorModel.getRed(pixel);
    }
    /**
     * return the red component of the pixel of the image  in java representation than can be summed up with other components to get the summed RGB valued
     * 
     * @param pixel
     *            the pixel number
     * @param colorModel
     * @return
     */
    public static int getRed(final int pixel, final ColorModel colorModel) {
        return colorModel.getRed(pixel);//<<16;
    }
}

Related Tutorials