Skip to main content

[JAVA2D] Using custom DataBuffer

1 reply [Last post]

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.(
at TestImage$MyPanel.(
at TestImage.(
at TestImage.main(

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

// 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(),
SinglePixelPackedSampleModel sm =
new SinglePixelPackedSampleModel(db.getDataType(),
width, height,
WritableRaster wr = Raster.createWritableRaster(sm, db, new Point(0,0));

Thanks much,

To unsubscribe, send email to and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to 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.
Joined: 2007-02-15

take a look at this thread

best regards