Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ObjectStreams -- Images

Posted on 2000-05-12
16
Medium Priority
?
221 Views
Last Modified: 2010-04-01
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
Comment
Question by:cmg05
  • 3
  • 3
  • 3
  • +5
16 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 2804005
what about deriving your own class from java.awt.Image and implement the Serailizable interface ... ?!

class MyImg extends Image implements Serializable
{ ...

nil_dib
0
 

Author Comment

by:cmg05
ID: 2804056
Why didn't SUN do that!!!!!!

Has anyone else already done this?

Code is what I need!
0
 
LVL 3

Expert Comment

by:ovidiucraciun
ID: 2804098
the serializable interface requires no code, it seems the sun did something till the end for the poor user ;)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:nil_dib
ID: 2804200
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
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2804247
>> 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
 
LVL 4

Expert Comment

by:nil_dib
ID: 2804287
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 2804451
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
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2804614
Try to pass image using sockets
0
 

Expert Comment

by:jaki_77
ID: 2804679
It is very easy when u use Sockets
0
 
LVL 7

Accepted Solution

by:
Sasha_Mapa earned 300 total points
ID: 2805206
>> 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
 
LVL 16

Expert Comment

by:heyhey_
ID: 2805295
>>  ... is create an array from your image ...

the only possible solution.

of course 'It is very easy when u use Sockets' :)
0
 
LVL 2

Expert Comment

by:stalefish
ID: 2805563
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
 

Author Comment

by:cmg05
ID: 2807946
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
 

Expert Comment

by:jaki_77
ID: 2809383
First u open that image file & convert it to byte then transfer that file from one machine to other.
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2810074
So, cmg05, didn't my suggestion on converting your image to an array of bytes and sending that instead work?
0
 

Author Comment

by:cmg05
ID: 2815233
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question