Of course.
Here is a proc that converts a binary image to a compatible RGB:
[code]
public static BufferedImage
convertToSinglePixelPackedSampleModel_BINARY(BufferedImage image) {
int[] bitMasks = new int[]{0x00ff0000, 0x0000ff00, 0x000000ff};
SinglePixelPackedSampleModel sampleModel = new
SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, image.getWidth(),
image.getHeight(), bitMasks);
int[] pixels = image.getRaster().getPixels(0, 0, image.getWidth(),
image.getHeight(), (int [])null);
for(int i=0; i<pixels.length; i++)
if (pixels[i] == 1)
pixels[i] = 0x00ffffff;
DataBufferInt d = new DataBufferInt(pixels, pixels.length);
WritableRaster destRaster = Raster.createWritableRaster(sampleModel, d,
null);
ICC_ColorSpace colorSpace = new
ICC_ColorSpace(ICC_Profile.getInstance(ColorSpace.CS_sRGB));
ColorModel colorModel = new DirectColorModel(colorSpace, 24, bitMasks[0],
bitMasks[1], bitMasks[2], 0, false, DataBuffer.TYPE_INT);
image = new BufferedImage(colorModel, destRaster, false, null);
return image;
}
[/code]
Now, here is the code that converts to compatible image:
[code]
public static BufferedImage toCompatibleImage(final BufferedImage image) {
long now = System.currentTimeMillis();
final BufferedImage compatible = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration()
.createCompatibleImage(image.getWidth(), image.getHeight(),
image.getTransparency());
ColorConvertOp op = new
ColorConvertOp(image.getColorModel().getColorSpace(),
compatible.getColorModel().getColorSpace(), null);
op.filter(image, compatible);
return compatible;
}
[/code]
If i take a binary image and convert it to RGB (first method), the
BufferedImage i get is faster to render (of course), but still at least 4 times
slower to render than in the case that i later convert to compatible image also.
The image before and after the conversion to compatible are identical.
What do i miss here?
Thank you,
Costas
[Message sent by forum member 'csterg' (csterg)]
http://forums.java.net/jive/thread.jspa?messageID=349437
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".