How can I convert System.Byte[] to Image? (C# window forms)

前端 未结 1 563
不思量自难忘°
不思量自难忘° 2020-12-10 15:51

I have a PictureBox control I want to display an image in it. I saved my images in a MS Access database with this data type: OLE Object. I find it

相关标签:
1条回答
  • 2020-12-10 16:38

    The simplest way is to use a MemoryStream and call Image.FromStream:

    byte[] data = (byte[]) dt.Rows[0]["IMAGE"];
    MemoryStream ms = new MemoryStream(data);
    pictureBox1.Image = Image.FromStream(ms);
    

    EDIT: If you run up against the problem described by Hans, you basically need to strip out that header. Once you have got a byte array with just the image data in, use the above code.

    0 讨论(0)
提交回复
热议问题