DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: binary serialization of a picturebox's image  (Read 5,794 times)

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
binary serialization of a picturebox's image
« on: May 21, 2009, 03:40 AM »
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)

later...

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?
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: binary serialization of a picturebox's image
« Reply #1 on: May 21, 2009, 10: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

r0bertdenir0

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 50
    • Participated in NANY Challenge Once
Re: binary serialization of a picturebox's image
« Reply #2 on: May 22, 2009, 07: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.

Original address: https://www.donationcoder.com/forum/index.php?topic=18406.0