List of usage examples for java.awt.image DirectColorModel getComponents
public final int[] getComponents(Object pixel, int[] components, int offset)
From source file:SampleAWTRenderer.java
private int[] processImage(Buffer buf) { int[] data = (int[]) buf.getData(); int[] ret = new int[data.length]; RGBFormat fmt = (RGBFormat) buf.getFormat(); DirectColorModel dcm = new DirectColorModel(fmt.getBitsPerPixel(), fmt.getRedMask(), fmt.getGreenMask(), fmt.getBlueMask());/*from w w w. j ava2s . c o m*/ int[] rgb; int k; for (int i = 0; i < data.length; i++) { rgb = dcm.getComponents(data[i], null, 0); k = toGray(rgb); rgb[0] = rgb[1] = rgb[2] = k; ret[i] = dcm.getDataElement(rgb, 0); } return ret; }