I'm constructing a BufferedImage out of a byte array. Each pixel in
the array is 3 bytes long, ostensibly RGB but it's actually a
monochrome image so the three channels are always the same. My BI
construction is:
DataBuffer db = new DataBufferByte(buffer, buffer.length);
WritableRaster raster = Raster.createInterleavedRaster(db, width,
height, width*3, 3, new int[]{0}, null);
bi = new BufferedImage(indexedColorModel, raster, false, null);
and I draw with
g2.drawImage(bi, 0, 0, getWidth(), getHeight(), null);
Now here's the funny behavior: with the interpolation mode set to
nearest-neighbor, the image only displays when the panel size matches
the image size. If I resize the frame, the image surface goes black
(black is the zero color in my indexed color model). If I set the
interpolation mode to nearest-neighbor, it works just fine.
Any idea what in the world is going on here???
Ana - 29 Aug 2003 19:37 GMT
Ken, try to construct the BufferedImage directly. I found that much easier
to deal with. There are BufferedImage constructors for indexColorModel
support.
Ana
> I'm constructing a BufferedImage out of a byte array. Each pixel in
> the array is 3 bytes long, ostensibly RGB but it's actually a
[quoted text clipped - 16 lines]
>
> Any idea what in the world is going on here???
Ken DeLong - 30 Aug 2003 21:51 GMT
Well, the problem is that I don't have control over the format of the
data source. So I need to wrap the incoming array of bytes in a
DataBuffer, and I need access to the Raster factory methods to specify
which bytes are relevant.
> Ken, try to construct the BufferedImage directly. I found that much easier
> to deal with. There are BufferedImage constructors for indexColorModel
[quoted text clipped - 22 lines]
> >
> > Any idea what in the world is going on here???