Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating an Image from a rgb byte array

2 views
Skip to first unread message

E. Naubauer

unread,
Feb 18, 2006, 10:16:41 AM2/18/06
to
Hello

I'm trying to convert a byte array to an image Object via
MemoryImageSource. Three bytes together are a pixel, one byte per component:

[r][g][b][r][g][b][r][g][b][r][g][b][r][g][b]....

[] = one byte

This is the code:

int w = 176,h = 144;
Image output = null;
byte rgbBuffer[] = <image data with length w * h>

ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ComponentColorModel cm = new ComponentColorModel(cs,new int[]
{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);

output = Toolkit.getDefaultToolkit().createImage(new
MemoryImageSource(w, h, cm,dim, 0, w));


It works if I use a buffer of type int[] with packed RGBA values and
DataBuffer.TYPE_INT. However, with the above configuration, the image
remains black when drawn.

I'm starting to wonder if createImage actually works with interleaved
component data. I used a writable raster before, but it was awfully slow.

If anyone has a solution for this problem, please tell it.
Thanks in advance.

Knute Johnson

unread,
Feb 23, 2006, 5:58:09 PM2/23/06
to

You need a BufferedImage.

--

Knute Johnson
email s/nospam/knute/

0 new messages