This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to transfer a bufferedImage Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to transfer a bufferedImage Object?" Watch "How to transfer a bufferedImage Object?" New topic
Author

How to transfer a bufferedImage Object?

netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
HI, I have a BufferedImage in my client program.I want this to be sent to the server & converted into an ImageIcon only on the server.
code:
***************
public class SpyClient extends JFrame implements java.io.Serializable
{
--------
----
rob =new Robot();
Dimension d=Toolkit.getDefaultToolkit).getScreenSize();
System.out.println("dimension: "+d.toString());
bi=rob.createScreenCapture(new Rectangle(d));

soc2=new Socket("localhost",2000);
os=soc2.getOutputStream();
ObjectOutputStream ous=new ObjectOutputStream(os);
ous.writeObject(bi);
ous.flush();
os.close();
end of code:
***********
I receive an error that the object "java.awt.BufferedImage is not serializable".Is there any other way to do it?Please suggest me with some code as soon as possible.

Happy middling with java.
Netharam
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I would either change it to an ImageIcon first and send that, or save the BufferedImage as a jpeg file or something and send that to the server.

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15292
    
    6

I wrote a program that captures a screen image, then sends that image to a server and then the server opens the image in an image viewer (I was just doing some testing). You would just have to change the part where I open the image, to convert the image to an imageIcon. If you want the code, tell me your E-mail address and I will send you the code.


GenRocket - Experts at Building Test Data
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hi Nate I already tried using a jpeg file,but it is slower,moreover I don't want that image to be saved as file unless the users saves the image.So please reply with a code snippet of sending an ImageIcon instead of jpeg.
Hi Greg My e-mail ID can be viewed in my profile,anyway it is "netharam@yahoo.com".
Happy middling with java.
Netharam.
[ May 01, 2002: Message edited by: netharam ram ]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Here's some really short examples of this...

The client...


And the server...


Even sending a ImageIcon takes a while... a whole screenshot is quite a bit of information...

-Nate
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Thank U Nate,u'r code is very useful.I have a small doubt still.In this sample code u r saving the image to a JPEG file,but How to save it as a GIF file?Please reply this too.
Happy middling with java.
Netharam.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I thought I'd already answered that for you in this post?

-Nate
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Sorry Nate I was a bit confused.Sorry again for this post.Nate,is there anyway of getting back the BufferedImage from an ImageIcon?
Happy middling with java.
Netharam.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Here's a short code snippet from the Java Developers Almanac that shows how to convert an Image to a BufferedImage.



I got it from this page.

-Nate
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Thank u Nate.This code was very useful & the link too.
Happy middling with java.
Netharam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to transfer a bufferedImage Object?
 
Similar Threads
After screen Capture(to a Gif File)?????????
creating BufferedImage object in a servlet
BufferedImage OutOfMemoryError
BufferedImage to ServletOutputStream: Black Box
applet x/y coordinates