Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI return BufferedImage object from remote method

 
MSreekanth Reddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic