How to display a simple RGB buffer ?

Hi all,

I would like to display a byte[] containing RGB values created with a native graphic library (i take a video snapshot).

I've tryed to create an ImageIcon with its constructor :

public ImageIcon(byte[] imageData) but imageData is normally created by reading an image using Class.getResourceAsStream(), as described in doc.

Is it possible to use ImageIcon class to display RGB values or must I use a BufferedImage ?

I'm reading BufferedImage constructors and it seems to be a bit difficult : you have to indicate colorModel, SampleModel, DataBuffer, DataType, etc...

If I must create a BufferedImage, please how do I do ?

Thanks in advance

[710 byte] By [Doud] at [2007-9-26 7:23:57]
# 1
You might also want to take a look at MemoryImageSource. It takes an array of bytes in its constructor as well as a couple other things. Never used one myself, but it looks like it may suit your needs.Michael Bishop
mbishop78 at 2007-7-1 17:16:17 > top of Java-index,Security,Cryptography...
# 2

Easiest way will be to use MemoryImageSource and transfer your bytes to int's in RGB 0x00ff0000,0x0000ff00,0x000000ff format. Should be fairly easy, then call setPixels(int[]) and display your RGB image.

If you want speed, think about investing in the oriley Java2d book and using BufferedImages, as they are mch faster under java1.2 +

ericew at 2007-7-1 17:16:17 > top of Java-index,Security,Cryptography...