• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

ObjectStreams -- Images

I have writen a server, client program which sends objects.  It passes Strings OK but if you try and pump an Image through as an object it comes up with a NotSerializable exception.

How can I make my image serialisable!!  Or how else can I send My image.
0
cmg05
Asked:
cmg05
  • 3
  • 3
  • 3
  • +5
1 Solution
 
nil_dibCommented:
what about deriving your own class from java.awt.Image and implement the Serailizable interface ... ?!

class MyImg extends Image implements Serializable
{ ...

nil_dib
0
 
cmg05Author Commented:
Why didn't SUN do that!!!!!!

Has anyone else already done this?

Code is what I need!
0
 
ovidiucraciunCommented:
the serializable interface requires no code, it seems the sun did something till the end for the poor user ;)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nil_dibCommented:
mmhh ...
its not that easy...
first of all you have to derive from BufferedImage instead of deriving from Image, cause Image has several abstracts methodes which want to be overridden ... :(

I try to serialize a BufferedImage derived class but its seams that only the Object and not the Image data will be serailized ( saved it as file: only 1kB )

think you have to serialize the image bits seperate...

nil_dib
0
 
Sasha_MapaCommented:
>> class MyImg extends Image implements Serializable

Hmm, interesting... nil_dib, are you aware you will have to implement all the abstract methods of class Image or your MyImg will have to be abstract too? And even then you will have to direct way of getting a MyImg from an Image object?

>> Why didn't SUN do that!!!!!!
Because class Image is abstract, its actual implementation may or may not allow Serialization.

What I suggest for you to use is create an array from your image using java.awt.image.PixelGrabber and write the array instead of the Image object...
0
 
nil_dibCommented:
Sasha_Mapa,

> ...implement all the abstract methods
I see I see .. ( comment above )

BTW: when you are familiar with images/graphics take a look at http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10345853 

:)
nil_dib
0
 
heyhey_Commented:
the only solution is to use PixelGrabber to extract raw color information and MemoryImageSource to recreate the image on the remote computer. the 'standard Image object' uses a lot of native resources, so you just can't serialize it directly.
0
 
Ravindra76Commented:
Try to pass image using sockets
0
 
jaki_77Commented:
It is very easy when u use Sockets
0
 
Sasha_MapaCommented:
>> What I suggest for you to use is create an array from your image using java.awt.image.PixelGrabber and write the array instead of the Image object...
0
 
heyhey_Commented:
>>  ... is create an array from your image ...

the only possible solution.

of course 'It is very easy when u use Sockets' :)
0
 
stalefishCommented:
First, if you can get the raw bytes for the gif or jpg image, I would suggest send those instead of the bytes created from the PixelGrabber... you will be sending compressed data instead. Otherwise as people suggested above,grabbing the pixels and sending the bytes will work as well.

The other option, if you are using Swing, is to Send an ImageIcon object which is Serializable.

0
 
cmg05Author Commented:
Hey guys!  Geez.  You keep mentioning that It would be simplw using sockets?

I have a socket open through which I have piped a Object writer and reader,  how else could I have sent my Image through a socket?
0
 
jaki_77Commented:
First u open that image file & convert it to byte then transfer that file from one machine to other.
0
 
Sasha_MapaCommented:
So, cmg05, didn't my suggestion on converting your image to an array of bytes and sending that instead work?
0
 
cmg05Author Commented:
Yep it worked eventually.

Took me a while, It was simple to convert to an Integer array,  but then writing the array was hard, I had to create a loop, wich was emensly slow, then I created a vetor and sent the vector which was much quicker, If you were thinking diferrently, (ie a faster method) I would still apreciate your coments.  (ie I still have a loop creating the vector!)
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 3
  • 3
  • 3
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now