I'm trying to create a BufferedImage that'll read the image data from disk.
So I wrote a DataBuffer subclass that reads from a file. This data buffer is
TYPE_INT, but I get an exception saying that I need an integer data buffer:
java.awt.image.RasterFormatException: IntegerComponentRasters must
haveinteger DataBuffers
at sun.awt.image.IntegerComponentRaster.<init>(Unknown Source)
at sun.awt.image.IntegerInterleavedRaster.<init>(Unknown Source)
at sun.awt.image.IntegerInterleavedRaster.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at TestImage$MyPanel.<init>(TestImage.java:131)
at TestImage$MyPanel.<init>(TestImage.java:105)
at TestImage.<init>(TestImage.java:91)
at TestImage.main(TestImage.java:33)
Any idea (1) why IntegerComponentRaster is throwing this even though the
data buffer is TYPE_INT, or (2) how to create a buffered image with a custom
data buffer without getting such an error?
Here's the code I'm using, where DataBufferIntFile is my file-referencing
DataBuffer:
// from BufferedImage (for TYPE_INT_RGB)
DirectColorModel cm = new DirectColorModel(24,
0x00ff0000, // Red
0x0000ff00, // Green
0x000000ff, // Blue
0x0 // Alpha
);
DataBufferIntFile db = new DataBufferIntFile(dataFile);
// from DirectColorModel.createCompatibleWritableRaster
int[] bandmasks = new int[] {cm.getRedMask(),
cm.getGreenMask(),
cm.getBlueMask()};
SinglePixelPackedSampleModel sm =
new SinglePixelPackedSampleModel(db.getDataType(),
width, height,
bandmasks);
WritableRaster wr = Raster.createWritableRaster(sm, db, new Point(0,0));
...
Thanks much,
Brian
===========================================================================
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".