GraphicsConfiguration graphicsConfiguration = GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
// Attempt to use an optimized buffered image to avoid an additional
// color space conversion on each redraw.
BufferedImage optimalImage = graphicsConfiguration.createCompatibleImage(width, height, Transparency.OPAQUE);
ColorModel optimalCm = optimalImage.getColorModel();
int redIndex = optimalCm.getRed(REFERENCE_PIXEL);
int greenIndex = optimalCm.getGreen(REFERENCE_PIXEL);
int blueIndex = optimalCm.getBlue(REFERENCE_PIXEL);
if (optimalCm.hasAlpha()) {