Read a picture from Access DB into PictureBox

前端 未结 5 1847
情深已故
情深已故 2021-01-20 17:33

I have been trying to read a picture saved in Access DB as a OLE object in a PictureBox in a C# windows Application.

The code that does this is presented below:

相关标签:
5条回答
  • 2021-01-20 18:15

    Do a google search for AccessHdr. You'll find references to AccessHdr.cpp and AccessHdr.h. These will illustrate what is need to extract the streams without the header.

    0 讨论(0)
  • 2021-01-20 18:18

    You can't read OLE objects so easily. In fact, it is bad practice to keep pictures as OLE objects in database.

    It is preferred to have em as BLOB objects or path and filename at some storage. AccessImagine can handle both scenarios for MS Access and C#. You can download it here - http://access.bukrek.net

    0 讨论(0)
  • 2021-01-20 18:19

    Your bytestream is corrupted somehow, becouse I tried the exact method of yours but filled the byte array with PNG data from a file instead.

    I would suggest creating two streams, one from the database, and one from the file that was the source of the image in the database. Then compare them byte by byte. If there is even one byte of diffrence, the database image data is corrupt.

    0 讨论(0)
  • 2021-01-20 18:24

    Unfortunately I have no good answer for you, but I can tell you that when I tried, I got the same results. Sometimes skipping the first 78 bytes of the byte array worked, sometimes it didn't.

    This is because the OLE Object datatype stores some kind of header in the field, so that Access knows what type of OLE Object it is. I could not find a reliable way to work out exactly where this header stopped and real data started, but I also gave up, so good luck :)

    0 讨论(0)
  • 2021-01-20 18:25

    You can try:

    pbPassport.Image = Image.FromStream(ms);
    
    0 讨论(0)
提交回复
热议问题