Meaningless Drivel is fun!
The moose likes Distributed Java and the fly likes RMI return BufferedImage object from remote method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI return BufferedImage object from remote method" Watch "RMI return BufferedImage object from remote method" New topic

RMI return BufferedImage object from remote method

MSreekanth Reddy

Joined: Mar 06, 2005
Posts: 1
I have problem while returning a BufferedImage object from a remote method
That is:

---------- Run ----------
java.rmi.UnmarshalException: error unmarshalling return;
nested exception is: writing aborted; java.awt.image.BufferedImage

My Code is:
Client Program:

import java.rmi.*;
import java.awt.image.BufferedImage;
public class HelloClient
BufferedImage bi;

Remote r=Naming.lookup("rmi://localhost:1099/Helloss");
Hello h=(Hello)r;

System.out.println("BufferedImage Returned");

catch(Exception a)

public static void main(String rags[]) throws Exception
HelloClient ss=new HelloClient();
}// class
import java.rmi.*;
import java.rmi.server.*;
import java.awt.image.BufferedImage;
public class HelloImpl extends UnicastRemoteObject implements Hello

public HelloImpl() throws RemoteException

public BufferedImage sayHello() throws RemoteException

BufferedImage bi = new BufferedImage(10,10,10);

return bi;

Remote Interface:
import java.rmi.*;
import java.awt.image.BufferedImage;
public interface Hello extends Remote

public BufferedImage sayHello() throws RemoteException;

Plz give me sloution it will be very helpful for me. Thanking You
Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
The problem is because of non-serialized instance passing.

BufferedImage class does not implement Serializable interface which is required so as to persist the instance details.

RMI supports only serialized instance to be passed as arguments or return type.

It would be better if you could pass the pixel array and reproduce the image from the other end.

Grab pixels into Array return it
int temp[];
int pixelsGrabbed[] = bImage.getRGB(0,0,width,height,temp,0,width);
return pixelsGrabbed;
int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)

Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a portion of the image data.

Reproduce the image with the grabbed pixels
BufferedImage bImage=Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(Imagewidth, Imageheight, pixelsGrabbed, 0,Imagewidth));

Hope this helps

Also See

[ March 06, 2005: Message edited by: roshini sridhar ]
I agree. Here's the link:
subject: RMI return BufferedImage object from remote method
jQuery in Action, 3rd edition