Skip to main content

[JAVA2D] Using custom DataBuffer

1 reply [Last post]
Anonymous

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.(Unknown Source)
at sun.awt.image.IntegerInterleavedRaster.(Unknown Source)
at sun.awt.image.IntegerInterleavedRaster.(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at TestImage$MyPanel.(TestImage.java:131)
at TestImage$MyPanel.(TestImage.java:105)
at TestImage.(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 listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shikida
Offline
Joined: 2007-02-15
Points: 0

take a look at this thread

http://forums.java.net/jive/thread.jspa?threadID=23403&tstart=0

best regards