avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • November 12, 2018, 08:41 PM
  • Proudly celebrating 13 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: binary serialization of a picturebox's image  (Read 2832 times)


  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,176
    • View Profile
    • Donate to Member
binary serialization of a picturebox's image
« on: May 20, 2009, 10:40 PM »
I used to know how to do this; in fact, I actually did it a couple years ago in a NANY app.  But I can't seem to remember exactly how to go about now...

Here's what I'm trying to do, in a C# winform app:

1. load a picture (PNG, GIF, BMP, JPG) into a picturebox control
2. click Save to binary serialize the picturebox's image to disk as "myimg" (no extension)


1. restart program, which opens with a picbox with no image showing
2. click the Load button to deserialize "myimg" and place the image in the picbox

I can do serialize/deserialize in a snap with strings and numbers, but for some reason I'm not remembering how to do an image.  Any help?


  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,134
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: binary serialization of a picturebox's image
« Reply #1 on: May 21, 2009, 05:23 AM »
Why do you want to de/serialize a picture? Doesn't this work on the raw/decompressed image contents, thus bloating up storage size?
- carpe noctem


  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 49
    • View Profile
    • Donate to Member
Re: binary serialization of a picturebox's image
« Reply #2 on: May 22, 2009, 02:58 PM »
I think f0dder is right. I tried 2 do this in VB 4 a picture database app by writing the picture to an IStream & it worked great to let COM do the serial/deserialize hard work, but then I noticed the file size! >:(
The technique is used was 2 create a wrapper class for the picture object - you can give it a Load method that that calls yr normal method of loading a picture from file, but yr Load method will also create a char array & copy the actual file into that array.
So you are loading the file into a normal picture object & uncompressing it, but also saving the original compressed file in wateva format it may be.
To deserialize, write the array to a file & read the file.
If you wanna put in the effort to make it faster then you could probably find a way to deserialize the memory char array directly.

But yeah, you have to approach the serialize/deserialize thing differently when dealing with compressed data.