Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Creating an Image from a rgb byte array

Visto 2 veces
Saltar al primer mensaje no leído

E. Naubauer

no leída,
18 feb 2006, 10:16:4118/2/06
a
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

no leída,
23 feb 2006, 17:58:0923/2/06
a

You need a BufferedImage.

--

Knute Johnson
email s/nospam/knute/

0 mensajes nuevos