File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI return BufferedImage object from remote method" Watch "RMI return BufferedImage object from remote method" New topic
Author

RMI return BufferedImage object from remote method

MSreekanth Reddy
Greenhorn

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: java.io.WriteAbortedException: writing aborted;
java.io.NotSerializableException: java.awt.image.BufferedImage

My Code is:
Client Program:

import java.rmi.*;
import java.awt.image.BufferedImage;
public class HelloClient
{
BufferedImage bi;
HelloClient()
{
try{

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

bi=h.sayHello();
System.out.println("BufferedImage Returned");

}
catch(Exception a)
{
System.out.println(a);
}
}

public static void main(String rags[]) throws Exception
{
HelloClient ss=new HelloClient();
}//main()
}// class
Implementation:
import java.rmi.*;
import java.rmi.server.*;
import java.awt.image.BufferedImage;
import java.io.*;
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
Reference

Roshini.S
[ March 06, 2005: Message edited by: roshini sridhar ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI return BufferedImage object from remote method