Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Creating an Image from a rgb byte array

Reply
Thread Tools

Creating an Image from a rgb byte array

 
 
E. Naubauer
Guest
Posts: n/a
 
      02-18-2006
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,Dat aBuffer.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.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      02-23-2006
E. Naubauer wrote:
> 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,Dat aBuffer.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.


You need a BufferedImage.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert form byte[4] to Int32 while retaining the binary value of the byte array jeff@foundrymusic.com C++ 20 09-07-2009 08:54 PM
Colorsmart RGB or Adobe RGB? Morton Digital Photography 2 12-14-2007 01:47 AM
Converting a Primative byte array to a Byte array object Kirby Java 3 10-08-2004 03:01 AM
Get RGB array from image Riri Java 6 01-27-2004 10:39 AM
Appending byte[] to another byte[] array Bharat Bhushan Java 15 08-05-2003 07:52 PM



Advertisments