Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get an image from the system clipboard (Clipboard.GetImage()) and serialize it to a file. The end goal would be to, at a later time, deserialize this image and put it back in the clipboard.

I can't figure out how to successfully serialize the image. I tried creating a serializeable class that contains an image object, but I get the exception

"The type System.Drawing.Bitmap was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."

I tried using XmlInclude but am either doing it wrong or it does not resolve the problem.

Has someone done this before?
Posted
Comments
William Winner 3-Sep-10 16:10pm    
Why do you need to serialize it? Why can't you just use the Image.Save Method?

Why don't you use the Image.Save method?
:)
 
Share this answer
 
unless there is additional information that you need to save along with the image there is no need for serializing it .. with that said if you happen to desperately serialize it, first read it in a byte array and use the byte array in your serializable class.

Image img = Clipboard.GetImage();
            MemoryStream ms = new MemoryStream();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imgByteArray= ms.ToArray();


hope this helps
good luck
 
Share this answer
 
If you want to Serialize a Bitmap, then do nothing!
It is already serialized! In memory and on disk.
Just do what the other told you. Save it on disk as it is.
And if you insist in making an ISerializable class, when there is no need to, I will start suspecting... "homework".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900