I have a picture as a byte array. How can I display this picture in a Picture Box?
Printable View
I have a picture as a byte array. How can I display this picture in a Picture Box?
That's tricky. Use BitBlt Api function. You have the byte array (and you know the width and height of the bitmap... color depth...). Well, I use a technique, but it involves creating a bitmap. Here's some pointers, maybe will help.
1. Create a device dependent bitmap (using CreateDIBitmap, study BITMAPINFO, BITMAPINFOHEADER structures) using the byte array.
2. Then create a DC in memory (CreateCompatibleDC, compatible with the PictureBox' own DC) and select the previously created bitmap in it (SelectObject)
3. Copy the bits from that DC to the picturebox with BitBlt. Powerfull function BitBlt yes...
Don't forget to delete all objects you created, otherwise you will not be able to see many bitmaps (trust me..)