Hi,
> I'm writing a Java server application which sends (via socket) an image
> to an applet.
Good luck. Image objects are not serializable. In other words, they are
not willing to be sent over a network. I encountered the same problem in
my work. The reason, or so Sun claims: Image objects are stored in a
OS-dependent manner. Here's a workaround:
import java.awt.image.*;
Image image = (your image);
int w = (width of the image);
int h = (height of the image);
int pixels = new int[w*h];
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException ie) {
}
Send that int array to the client. On the client side,
int[] pixels = (int array from the server);
int w = (image width);
int h = (image height);
Image image = createImage(new MemoryImageSource(w, h, pixels, 0, w));
> What is wrong?
> Does anyone know if there is a better way to send image via socket?
I don't know if I'd call that BETTER, but it works :)
dstn