• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to transfer a bufferedImage Object?

 
netharam ram
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
netharam ram
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I'd already answered that for you in this post?

-Nate
 
netharam ram
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic