I think that in order to send images through remote methods they have to be
saved to a byte array using the PixelGrabber, or something like this...
Can anyone tell me exactly how to do it, and if possible provide a piece of
code?
Thanks a lot,
please send replies to both the newsgroup and n.o...@lancaster.ac.uk
noelia.
The bad news: java.awt.Image is not serializable because it is platform
dependent.
The good news: If you are using Swing, the ImageIcon class is serializable.
The bad news: It will not be compressed and will take a lot of space (24 or
32 bits per pixel).
The good news: With Java2D (or is it JMF or JAI?) there are methods to turn
an image into a JPEG or PNG etc.
--
--- Dale King
/*_image, _w, _h are class members that I keep around*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
s.defaultWriteObject();
if(_image != null ) {
int pixels[] = new int[_w * _h];
PixelGrabber pg = new PixelGrabber(_image, 0, 0, _w, _h, pixels,
0, _w);
try { pg.grabPixels(); } catch (InterruptedException e)
{return;} // here we aren't
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {return;}
// going to do anything
if ((pg.getStatus() & ImageObserver.ERROR) != 0) {return;}
// if we fail to get the
// pixels
byte bytes[] = intArrayToByteArray(pixels); /*this is just a
routine that turns the int[] to a byte[]*/
s.write(bytes);
}
}
to deserialize:
/*_pixels, _w, _h are class members that I keep around*/
private void readObject(java.io.ObjectInputStream s)
throws java.lang.ClassNotFoundException, java.io.IOException {
s.defaultReadObject();
byte bytes[] = new byte[_w * _h * 4];
s.read(bytes);
_pixels = byteArrayToIntArray(bytes);/*this is just a routine that
turns the byte[] to an int[]*/
}
to reconstitute:
/*_image,_pixels, _w, _h are class members that I keep around*/
MemoryImageSource mis = new MemoryImageSource(_w, _h, _pixels, 0, _w);
_image = Toolkit.getDefaultToolkit().createImage(mis);
Dale King <Ki...@TCE.com> wrote in message
news:378df...@news.indy.tce.com...