Java examples for 2D Graphics:BufferedImage Color
Getting the Color Model of an Image
import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.PixelGrabber; public class Main { // This method returns the color model of an image public static ColorModel getColorModel(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { BufferedImage bimage = (BufferedImage) image; return bimage.getColorModel(); }/* w w w. j av a2s . co m*/ PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { } ColorModel cm = pg.getColorModel(); return cm; } }