int w = 1024, h = 1024; // or whatever you prefer ColorSpace xyzCS = ColorSpace.getInstance(ColorSpace.CS_CIEXYZ); ComponentColorModel cm = new ComponentColorModel(xyzCS, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = cm.createCompatibleWritableRaster(w, h); BufferedImage xyzImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
@Override protected BufferedImage createImage(int width, int height) { ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); WritableRaster raster = ccm.createCompatibleWritableRaster(width, height); return new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null); } }
@Override protected BufferedImage createImage(int width, int height) { ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); WritableRaster raster = ccm.createCompatibleWritableRaster(width, height); return new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null); } }
@Override protected BufferedImage createImage(int width, int height) { ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); WritableRaster raster = ccm.createCompatibleWritableRaster(width, height); return new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null); } }
@Override public WritableRaster createCompatibleWritableRaster(int w, int h) { if (pixelBits == 16) { int[] bandOffsets = new int[nChannels]; for (int i=0; i<nChannels; i++) bandOffsets[i] = i; SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_SHORT, w, h, nChannels, w * nChannels, bandOffsets); DataBuffer db = new DataBufferShort(w * h, nChannels); return Raster.createWritableRaster(m, db, null); } return helper.createCompatibleWritableRaster(w, h); }
@Override public Graphics2D prepare(Component component, Graphics2D graphicsArgument) { this.graphics = graphicsArgument; int width = component.getWidth(); int height = component.getHeight(); /* To convert to gray, we create a BufferedImage in the grayscale color * space into which the decorated component draws, and we output the * resulting image. The naive way to create the buffer is new * BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); but that * doesn't respect transparency. Hence the following more complicated * method. */ if (bufferedImage == null || bufferedImage.getWidth() < width || bufferedImage.getHeight() < height) { ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); WritableRaster raster = ccm.createCompatibleWritableRaster(width, height); bufferedImage = new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null); } bufferedImageGraphics = bufferedImage.createGraphics(); bufferedImageGraphics.setClip(graphicsArgument.getClip()); return bufferedImageGraphics; }
@Override public WritableRaster createCompatibleWritableRaster(int w, int h) { if (pixelBits == 16) { int[] bandOffsets = new int[nChannels]; for (int i=0; i<nChannels; i++) bandOffsets[i] = i; SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_SHORT, w, h, nChannels, w * nChannels, bandOffsets); DataBuffer db = new DataBufferShort(w * h, nChannels); return Raster.createWritableRaster(m, db, null); } return helper.createCompatibleWritableRaster(w, h); }
@Override public final Raster getRaster(final int x, final int y, final int w, final int h) { if (null == raster || raster.getWidth() != w || raster.getHeight() != h) { raster = ccm.createCompatibleWritableRaster(w, h); } final int lenY = y+h; final int lenX = x+w; for (int j=y; j<lenY; ++j) { for (int i=x; i<lenX; ++i) { raster.setDataElements(i-x, j-y, value); } } return raster; }
@Override public Graphics2D prepare(Component component, Graphics2D graphics) { this.graphics = graphics; int width = component.getWidth(); int height = component.getHeight(); /* To convert to gray, we create a BufferedImage in the grayscale color * space into which the decorated component draws, and we output the * resulting image. The naive way to create the buffer is new * BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); but that * doesn't respect transparency. Hence the following more complicated * method. */ if (bufferedImage == null || bufferedImage.getWidth() < width || bufferedImage.getHeight() < height) { ColorSpace gsColorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ComponentColorModel ccm = new ComponentColorModel(gsColorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); WritableRaster raster = ccm.createCompatibleWritableRaster(width, height); bufferedImage = new BufferedImage(ccm, raster, ccm.isAlphaPremultiplied(), null); } bufferedImageGraphics = bufferedImage.createGraphics(); bufferedImageGraphics.setClip(graphics.getClip()); return bufferedImageGraphics; }
@Override public WritableRaster createCompatibleWritableRaster(final int w, final int h) { if (pixelBits == 16) { final int[] bandOffsets = new int[nChannels]; for (int i = 0; i < nChannels; i++) bandOffsets[i] = i; final SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_SHORT, w, h, nChannels, w * nChannels, bandOffsets); final DataBuffer db = new DataBufferShort(w * h, nChannels); return Raster.createWritableRaster(m, db, null); } return helper.createCompatibleWritableRaster(w, h); }
@Override public WritableRaster createCompatibleWritableRaster(final int w, final int h) { if (pixelBits == 16) { final int[] bandOffsets = new int[nChannels]; for (int i = 0; i < nChannels; i++) bandOffsets[i] = i; final SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_SHORT, w, h, nChannels, w * nChannels, bandOffsets); final DataBuffer db = new DataBufferShort(w * h, nChannels); return Raster.createWritableRaster(m, db, null); } return helper.createCompatibleWritableRaster(w, h); }
final BufferedImage bi = new BufferedImage(paint.getComponentColorModel(), paint.getComponentColorModel().createCompatibleWritableRaster(width, height), false, null); final Graphics2D g = bi.createGraphics();
WritableRaster r = cm.createCompatibleWritableRaster(xSize, ySize); BufferedImage bi = new BufferedImage(cm, r, false, null);
cs = ColorSpace.getInstance(ColorSpace.CS_GRAY); colorModel = new ComponentColorModel(cs, new int[] { bpp }, false, true, Transparency.OPAQUE, dataType); raster = colorModel.createCompatibleWritableRaster(cols, rows); break; case 3: