I have edited this question to make it easier to understand.
I have an image file and I have to store the image data into an existing file in binary. And when that file gets opened in my program again, that binary data should be somehow read and that image displayed inside a picturebox. How would I go about doing this in C#?
Any help/suggestions much appreciated.
Thank you
jase
EDIT:
Because our files are of the following structure:
Control
"Text here"
Location
…And there will be many cases where there are more than one or a few controls in the same file like so:
Label
"This is a label"
23, 44
Label
"This is another label"
23, 64
LinkLabel
"This is a linkLabel"
23, 84
…
I don’t know where to place/save the following code:
Maybe inside the file like so…:
Image
"<controlLocationData type="Image">
<Data>
Base64 encoded image data here
</Data>
<FreeformLocation>60, 40</FreeforLocation>
</controlLocationData>"
60, 40
and then use this code below to save/load and display the image?…
var image = LoadBitMap("My Bitmap");
var stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
string base64Encoded = Convert.ToBase64String(stream.ToArray());
I would probably be inclined just create a block of base64 text in your file that represents the BMP bits.
Edit:
Looks like you are already on the right track here, I find that with these types of conversions, a couple of extension methods are pretty handy…
The format of your text file is no big deal, you just need to be able to index into it for your data, so Xml is a common format, but as I said, its just a case of finding the base64 block that you are after.