ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

binary serialization of a picturebox's image

(1/1)

kyrathaba:
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?

f0dder:
Why do you want to de/serialize a picture? Doesn't this work on the raw/decompressed image contents, thus bloating up storage size?

r0bertdenir0:
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.

Navigation

[0] Message Index

Go to full version