2

I worked on a project that i need to transfer GIF to the applet from server over TCP socket. The problem is that when i transfer the image it become static (the last frame displayed).

I tried to transfer (ICON) where i loaded the image on server side but it has the same result.

So, Is there any class to read animated gif so i can transfer it by ObjectOutputStream? or any way else?

Server Side:

ImageIcon icon = new ImageIcon("D:\\Data Files\\simu.gif");
Mat_out.writeObject(icon);

Client Side:

ImageIcon icon = (ImageIcon) Mat_in.readObject();
jLabel2.setIcon(icon);
Ali Zein
  • 113
  • 2
  • 9

1 Answers1

0
  1. Use one of the createImage(..) methods of toolkit methods of toolkit to load the image, but..
  2. Add a MediaTracker to ensure the entire image is loaded before transmitting it. (This can also work for the image returned from ImageIcon, but why create a GUI component that is not needed?)

Alternately load the entire byte[] of the image using a blocking method, and provide that to createImage(byte[]).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Does createImage() methods deal with animated images? as BufferedImage & ImageIO classes doesn't support animated & returns static (last frame) image. – Ali Zein Sep 10 '12 at 15:43
  • Thank U very much.. I tried the second option & it works ! :)) – Ali Zein Sep 10 '12 at 17:27
  • Glad you got it sorted. :) Re the animation frames, see [Show an animated BG in Swing](http://stackoverflow.com/questions/10836832/show-an-animated-bg-in-swing) for more details. – Andrew Thompson Sep 10 '12 at 18:24