Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Whiteboard app

Hi,
I am developing a tutor system consist of whiteboard, which will transmit the data to all the students connected to the system. Currently, I can do the drawings all on a panel.

I am looking for a way to get the image of the panel and transmit to the clients (broadcast) in every second. How can I do it?.. Please help me.
[340 byte] By [sara8305] at [2007-11-11 6:59:50]
# 1 Re: Whiteboard app
One way could perhaps be to "grab" the Image on your display, convert it
to a gif-file and transfer that to the others. If you use double buffering
you already have the (Buffered ?)Image ready for convertion.

Here is the source for a GifOutputStream, it converts a java.awt.Image to
a gif file.
sjalle at 2007-11-11 22:39:47 >
# 2 Re: Whiteboard app
Hi,
Thanks for the reply. But the thing is I am not sure how to grab the image from the panel. Do I need to use createImage ?
I tried a simple one which draws whatever on the Jpanel1 to the JPanel2. But it is only drawing blank rectangle.
Image x = null;
x = pnlMain.createImage(100,100);
jPanel1.getGraphics().drawImage(x,100, 100, this);

Is this the correct method?
Actually, I need to grab the image and export it as JPEG (to create it as a movie) which somehow I will pass to Java Media Framework for encoding and transmission to other clients. So, I dont really worry about the cleint part as the JMF will take care of it. The reason I am doing because I need to save the whiteboard activities as movie for replay.
Really need help in this. I am still new in Java. Thank you.
sara8305 at 2007-11-11 22:40:41 >
# 3 Re: Whiteboard app
Use the BufferedImage class for this.

Try using a double buffering; create a BufferedImage, get its Graphics,
then in your paint/update you do all the drawing to the graphics context
gotten from the BufferedImage. At the end of the paint/update you then
draw the BufferedImage onto the display Graphics (the g passed to paint).

The bufferedImage can be typecast to Image and you can use the
GifOutputStream to convert this into a gif file. I'm not sure what you mean by
"movie", - a 24 frames/sec would eat your disk fast...

How about an approach where you, at the click of ctrl-mouse export the
current BufferedImage to file using a naming convention like wb0001.gif,
wb0002.gif etc. ?

Anyway, I have included a sightly modified version of a very simple drawing
application I posted here a while ago. The modification is that I have
utilized the GifOutputStream class for saving the drawing.
sjalle at 2007-11-11 22:41:45 >
# 4 Re: Whiteboard app
Hi, sorry for the late reply. Thanks for the solution. Looks like I have been trying to solve problem the other way around (Get the image object of the panel after being drawn -which is wrong). Now I get the buffered image from the graphics before it is being pushed to the panel.
BufferedImage bi = (BufferedImage)this.refTuitionWhiteboard.getTuitionImage();

Actually, it's not 24 frames per second; I am transmitting it as H.263/RTP (using JMF) on 5 frames per second and 352x288 resolution. Therefore it didnt take that much space.
I will come back if I find any more problem. thanks.
sara8305 at 2007-11-11 22:42:44 >