Save Microsoft Access database OLE Objects (jpegs) to disk via VB.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZG1idXNv?=

    Save Microsoft Access database OLE Objects (jpegs) to disk via VB.

    I have an Access database with a table named 'tblMedia'. In tblMedia I have a
    field named 'Media' that is defined as an 'OLE Ojbect' field. In this Media
    field, I have pictures, they are jpegs. I'm using VB.NET 2005 and I would
    like to open the Access database and write the OLE Objects to the file system.

    Here's what I got and it's not working.

    'Open connection to the Access database
    OpenConnection( )

    Dim Command As New OleDbCommand("S ELECT * FROM TBLMEDIA WHERE
    [MediaType]='Mug shot'", _DBConn)
    Dim Reader As OleDbDataReader = Command.Execute Reader()
    Dim picture As Image = Nothing

    'Read each line of TBLMEDIA and write out to Media file
    While Reader.Read
    'Place image on the clipboard
    Dim pictureData As Byte() = CType(Reader.Ge tValue(3), Byte())

    Using stream As New IO.MemoryStream (pictureData)
    picture = Image.FromStrea m(stream)
    End Using

    My.Computer.Cli pboard.SetImage (picture)

    'Get the image from the clipboard
    If My.Computer.Cli pboard.Contains Image() Then
    picture = My.Computer.Cli pboard.GetImage

    'Write the image to a disk file
    picture.Save(Me .txtDestFolder. Text & "\" &
    Reader.GetValue (1).ToString & ".jpg")
    End If
    End While


    I get a 'Parameter is not valid.' error on this line above:
    picture = Image.FromStrea m(stream)

    --
    Dave B.
  • WenYuan Wang [MSFT]

    #2
    RE: Save Microsoft Access database OLE Objects (jpegs) to disk via VB.

    Hello Dave,

    I understood you want to get images from MS Access database, but the
    application failed with the line "Image.FromStre am(stream)". The error
    message is "Parameter is not valid". If I misunderstood anything here,
    please correct me.

    The array of bytes you received from OLE Ojbect filed contains a 78-byte
    prefix that has nothing to do with the image. Those bytes are just the
    header created when the image was added as an OLE object to MS Access. It
    must undergo the following modification to work with the OLE field of MS
    Access database:

    Using stream As New IO.MemoryStream ()
    stream.Write(pi ctureData,78, pictureData.Len gth - 78 )
    picture = Image.FromStrea m(stream)
    End Using

    Hope this helps. Please try this method and let me know the result. If you
    face any further issue, feel free to update here again. We are glad to
    assist you.

    Have a great day,
    Best regards,

    Wen Yuan
    Microsoft Online Community Support
    =============== =============== =============== =====
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • =?Utf-8?B?ZG1idXNv?=

      #3
      RE: Save Microsoft Access database OLE Objects (jpegs) to disk via

      Wen,

      I commented out my code and pasted yours in and I still get the same error
      message "Parameter is not valid".

      Any other suggestions?
      --
      Dave B.


      "WenYuan Wang [MSFT]" wrote:
      Hello Dave,
      >
      I understood you want to get images from MS Access database, but the
      application failed with the line "Image.FromStre am(stream)". The error
      message is "Parameter is not valid". If I misunderstood anything here,
      please correct me.
      >
      The array of bytes you received from OLE Ojbect filed contains a 78-byte
      prefix that has nothing to do with the image. Those bytes are just the
      header created when the image was added as an OLE object to MS Access. It
      must undergo the following modification to work with the OLE field of MS
      Access database:
      >
      Using stream As New IO.MemoryStream ()
      stream.Write(pi ctureData,78, pictureData.Len gth - 78 )
      picture = Image.FromStrea m(stream)
      End Using
      >
      Hope this helps. Please try this method and let me know the result. If you
      face any further issue, feel free to update here again. We are glad to
      assist you.
      >
      Have a great day,
      Best regards,
      >
      Wen Yuan
      Microsoft Online Community Support
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.
      >
      >

      Comment

      • WenYuan Wang [MSFT]

        #4
        RE: Save Microsoft Access database OLE Objects (jpegs) to disk via

        Hello Dave,
        Thanks for your reply,

        It seems you send the mail to a wrong address.
        My alias is v-wywang@microsof t.com. I'm waiting for your reply.
        As we discussed before, you can get me at v-wywang@microsof t.com.

        I created an Access DB, and insert some jpeg images into it. Finally, I
        reproduced it.
        After research, I found 78 byte is used for BMP image. It doesn't work fine
        with JPEG image file. Under my test, the offset for JPEG image is 189.but
        I'm not sure. It seems the number dependens on the size of file.I need
        perform further research.

        Is it possible for you to give me your email Address? Thereby, I can pass
        the information for you as soon as possible.(again , my alias is
        v-wywang@microsof t.com. You can send an email to me.) If you have any more
        concern, please also feel free to update here. We are glad to assist you.

        Have a great day.
        Best regards,

        Wen Yuan
        Microsoft Online Community Support
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • =?Utf-8?B?TWFyYw==?=

          #5
          RE: Save Microsoft Access database OLE Objects (jpegs) to disk via

          WenYuan,

          I have the same problem that is 'parameter not valid'. Do you have any
          developments on the offset value for JPEG images? How do you determine if the
          offset value is 189 or something else?

          Cheers,
          Marc

          Comment

          Working...