slow network image transfers

M

Morris

Hi,

I've been looking for ways to send images across the network to other
machines for certain processing applications. Speed is the most
important factor in this situation.

I initially tried writing image icons, but this was much too slow. I
then tried using PixelGrabber coupled with MemoryImageSource. This
proved to be much faster (about a half second to transfer a 1024x768
image). However, after a change to jsdk 1.5, the speed dropped to
nearly 4 seconds for the same image.

I'm using an ObjectOutputStream.writeObject() with the pixel object
obtained from the PixelGrabber. I'm using various versions of Windows
and it seems to happen on all of them.

I assume there is some socket parameter or something that needs to be
adjusted in the new version. I seem to remember seeing a post about a
network cache setting somewhere?

On a related front, is there a better way to do this? I know the
exact size of each image and therefore could just write each int in
the array returned by PixelGrabber to the connection if that would be
faster than doing a writeObject().

Thanks for any suggestions.

morris
 
A

Andrei Kouznetsov

I've been looking for ways to send images across the network to other
machines for certain processing applications. Speed is the most
important factor in this situation.

I initially tried writing image icons, but this was much too slow. I
then tried using PixelGrabber coupled with MemoryImageSource. This
proved to be much faster (about a half second to transfer a 1024x768
image). However, after a change to jsdk 1.5, the speed dropped to
nearly 4 seconds for the same image.

I'm using an ObjectOutputStream.writeObject() with the pixel object
obtained from the PixelGrabber. I'm using various versions of Windows
and it seems to happen on all of them.

I assume there is some socket parameter or something that needs to be
adjusted in the new version. I seem to remember seeing a post about a
network cache setting somewhere?

On a related front, is there a better way to do this? I know the
exact size of each image and therefore could just write each int in
the array returned by PixelGrabber to the connection if that would be
faster than doing a writeObject().

yes, you should send pixel array (int[] or byte[]).
Good idea is to use ZipOutputStream and ZipInputStream.
 
M

Morris

Andrei Kouznetsov said:
yes, you should send pixel array (int[] or byte[]).
Good idea is to use ZipOutputStream and ZipInputStream.

Hi,

Thanks, I've changed to using the int[] method. I've enclosed bits of
relavent code below for anyone interested.

I wonder if the time required to create a ZIP stream is longer than
the time to just send the data directly though. This would probably
be an interesting test for another time.

FYI, my transfer time is about 150-200 ms for a 1024x768 image. This
is with an AMD64 3200 processor, 1GB of memory and gigabit network.

thanks,

morris



BufferedImage bi = new BufferedImage(1024, 768,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics( );

public boolean connect() {
try {
socket = new Socket(ServerAddress, 1999);
dos = new DataOutputStream(new
BufferedOutputStream(socket.getOutputStream(), 1024));
return true;
}
catch(Exception e) {
System.out.println(e.getMessage());
return false;
}
}

public void sendImage(Image img) {
g2d.drawImage(img, null, null);
pixels = getPixels(bi);
try {
int[] pixInt = (int[])pixels;
for (int i = 0; i < pixInt.length; i++) {
dos.writeInt(pixInt);
}
dos.flush();
}
catch(Exception e) {System.out.println(e.getMessage());}
}

public Object getPixels(BufferedImage bimg) {
PixelGrabber grabber = new PixelGrabber(bimg, 0, 0, -1, -1, true);
try {
grabber.grabPixels();
}
catch (InterruptedException e) { }
Object pix = grabber.getPixels();
return pix;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top