How to convert image file to byte and save to .mdb?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbKen
    New Member
    • Feb 2016
    • 1

    How to convert image file to byte and save to .mdb?

    Hello, I was about to create application that can save image from imagebox that has a webcam interface on it. I've been already save the byte but i guess my conversion is wrong because i cant view OLE object data from database to My imagebox.
    Error: " Unable to bind to field or DataMember: 'Picture' "
    I really need Help. Sorry for my bad english
    This is my Whole code on save button.

    Code:
    Private Sub cmdsave_Click()
    OpenDB
    rs.Open "tblimg", db, adOpenKeyset, adLockPessimistic, adCmdTable
    Dim bytData() As Byte, PicInfo As BITMAP
    GetObject Image1.Picture, Len(PicInfo), PicInfo
    ReDim bytData((PicInfo.bmWidth * PicInfo.bmHeight * 3) - 1) As Byte
    GetBitmapBits Image1.Picture, UBound(bytData), bytData(0)
    With rs
    .AddNew
    .Fields("Picture").AppendChunk bytData
    .Fields("Desc") = Label2.Caption
    .Update
    End With
    If Dir(App.Path & "\myPic", vbDirectory) = "" Then MkDir (App.Path & "\myPic")
    File1.Path = App.Path & "\myPic"
    'File1.Pattern = "*.bmp"
    File1.Pattern = "*.jpg"
    File1.Refresh
    Dim Maxnum As Integer, ii As Integer
    For ii = 0 To File1.ListCount - 1
        If Left(File1.List(ii), 1) = "p" Then
            If CInt(Mid(File1.List(ii), 2, Len(File1.List(ii)) - 4)) > Maxnum Then
                Maxnum = CInt(Mid(File1.List(ii), 2, Len(File1.List(ii)) - 4))
            End If
        End If
    Next
        Picture1.Picture = Image1.Picture
        'SavePicture Image1.Picture, App.Path & "\myPic\p" & Maxnum + 1 & ".bmp"
        SAVEJPEG App.Path & "\myPic\p" & Maxnum + 1 & ".jpg", 100, Me.Picture1
    Set rs = Nothing
    db.Close: Set db = Nothing
    End Sub
    Last edited by Rabbit; Feb 28 '16, 05:55 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
Working...