Loading PicBox from memory (binary data)
Hi all.
I need to load a PictureBox with image data that I have in memory during the running of my code. I could save the image to the HD and the use the LoadPicture to load it, but that involves reading/writing to the HD, which I am trying to avoid.
Does anybody know of anyway to do this? I know the hDC of the PictureBox so I am hoping there's some whizzy GDI API call I can use to simply transfer my memory contents into the PictureBox.
Any advice or suggestions much appreciated :)
inf.
Re: Loading PicBox from memory (binary data)
Quote:
Originally Posted by infaddict
... I am hoping there's some whizzy GDI API call I can use to simply transfer my memory contents into the PictureBox ...
What exactly whould that mean?
Re: Loading PicBox from memory (binary data)
Hi RhinoBull and thanks for your reply. Let's see if I can explain my situation some more...
My code successfully allows the user to pick an MP3 file from their HD and then examines the ID3 tags inside the MP3, and picks out Artist, Song, Album etc. If the ID3 tags are version 2, my code then successfully looks for an embedded Album Cover Picture inside the MP3. If it finds one, I would like to display that image inside a PictureBox control on my form.
The image data is held in my code in a Byte array and I also have it as a String. I have successfully written that data to disk (e.g. to C:\test.jpg) and then loaded the PictureBox e.g. pic1.Picture = LoadPicture("C:\test.jpg") and the image appears fine. However, I would like to achieve the same result (i.e. the image appears in the PictureBox), without have to save the data to a disk file and then load it back from disk into the PictureBox.
Therefore, to summarise, I would like to take the Byte Array or String of Binary data, and load it directly to the PictureBox to show the image. I can't see any built-in method of the PictureBox to do this, so I'm guessing some sort of API call is needed, using the hDC of the PictureBox.
Any help or direction much appreciated :wave:
Edit : Forgot to say that the image format will mostly be JPEG but may also be PNG. I'd be happy to just get JPEG working first and worry about PNG later. ;)
Re: Loading PicBox from memory (binary data)
Quote:
Originally Posted by infaddict
... to summarise, I would like to take the Byte Array or String of Binary data, and load it directly to the PictureBox to show the image...
Perhaps sample from the following article will work for you:
Can we view a picture from its memory data?