Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    12

    Unanswered: How to save a pic from access (binary data)?

    How to save a pic from access (binary data)? How to convert a pic to binary data? I am a beginner.

    Thanks.
    Last edited by yikkang; 12-01-05 at 03:42.

  2. #2
    Join Date
    Nov 2004
    Posts
    30
    '-------------------------------------------------------
    ' FUNCTION : ReadImage
    ' Purpose : Reads the image from the database
    ' Input : argMySql - the Query string to open the record set
    ' argImageControl - the Image Control on your form
    ' Output : True if the image is loaded successfully
    ' IMPORTANT The first field should be image field
    '--------------------------------------------

    Public Function ReadImage(argMySql As String, argImageControl As Image) As Boolean
    On Error GoTo MyError
    '------------start loading image data
    Dim lngOffset As Long
    Dim lngTotalSize As Long
    Dim strChunk As String
    Dim strSQL As String
    strSQL = argMySql
    DataFile = 1
    'open the record set
    Set adoPrimaryRs = New ADODB.Recordset
    If adoPrimaryRs.State = adStateOpen Then adoPrimaryRs.Close
    With adoPrimaryRs
    .Open strSQL, m_cnnGlobal, adOpenStatic, adLockReadOnly
    If .RecordCount = 0 Then
    Set argImageControl.Picture = Nothing
    adoPrimaryRs.Close
    Set adoPrimaryRs = Nothing
    ReadImage = False
    Exit Function
    End If
    End With

    Open App.Path & "\tmpPic.tmp" For Binary Access Write As DataFile
    lngTotalSize = adoPrimaryRs.Fields(0).ActualSize
    chunks = lngTotalSize \ ChunkSize
    SmallChunks = lngTotalSize Mod ChunkSize
    ReDim Chunk(ChunkSize)
    Chunk() = adoPrimaryRs.Fields(0).GetChunk(ChunkSize)
    Put DataFile, , Chunk()
    lngOffset = lngOffset + ChunkSize
    Do While lngOffset < lngTotalSize
    Chunk() = adoPrimaryRs.Fields(0).GetChunk(ChunkSize)
    Put DataFile, , Chunk()
    lngOffset = lngOffset + ChunkSize
    Loop
    Close DataFile
    argImageControl.Picture = LoadPicture(App.Path & "\tmpPic.tmp")
    Kill App.Path & "\tmpPic.tmp"
    '---------- end loading image data
    adoPrimaryRs.Close
    Set adoPrimaryRs = Nothing
    ReadImage = True
    Exit Function
    MyError:
    MsgBox "Error while writing the ImageData" & vbCrLf & Err.Description, vbCritical, "Images"
    Close DataFile
    MsgBox Err.Description
    Set adoPrimaryRs = Nothing
    ReadImage = False
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •