E
E. Naubauer
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][r][g][r][g][r][g][r][g]....
[] = 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.
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][r][g][r][g][r][g][r][g]....
[] = 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.