PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
vb 6.0 convert base64 image data into .bmp image-VBForums
Results 1 to 16 of 16

Thread: vb 6.0 convert base64 image data into .bmp image

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    4

    Exclamation vb 6.0 convert base64 image data into .bmp image

    Hi guys,

    I have requirement to create .bmp or .png or .jpeg image from data received from a source in base64 format. i want to convert this text data(base 64) into a .bmp image file. our application is developed in vb 6.0

    kindly help!!!!!

    Rahul.

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    4

    Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by rahuls.8333 View Post
    Hi guys,

    I have requirement to create .bmp or .png or .jpeg image from data received from a source in base64 format. i want to convert this text data(base 64) into a .bmp image file. our application is developed in vb 6.0

    kindly help!!!!!

    Rahul.
    use this link for sample base 64 image datahttps://drive.google.com/open?id=1se...ZEOF7RCa3z29nr

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,646

    Re: vb 6.0 convert base64 image data into .bmp image

    Name:  sshot.png
Views: 105
Size:  1.1 KB

    Using WIA 2.0... or you might write more code and do it in GDI+ Flat API calls instead.
    Attached Files Attached Files

  4. #4
    Addicted Member
    Join Date
    Sep 2015
    Posts
    174

    Re: vb 6.0 convert base64 image data into .bmp image

    Name:  WBC.png
Views: 104
Size:  4.7 KB
    This is a sample to convert Base64 into a bitmap.

    May I ask what hematology analyzer is this?!


    P.S :
    * The Base64 Decoding function was freely available on the Internet
    ** The function for saving byte array into a bitmap was kindly provided by Olaf Schmidt
    Attached Files Attached Files
    Last edited by labmany; Sep 29th, 2019 at 10:28 PM.

  5. #5
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,582

    Re: vb 6.0 convert base64 image data into .bmp image

    @labmany: If you pinched the Decode64 function from VB - Fast Base64 Encoding and Decoding thread why did you choose the slower and more bloated pure VB6 implementation that returns (inconvenient) string that has to be treated w/ StrConv before saving to a binary BMP file?

    FYI, here is the shorter (and faster, and LAA) FromBase64Array function from the same thread
    thinBasic Code:
    1. ' Attribute VB_Name = "mdFromBase64Array"
    2. Option Explicit
    3.  
    4. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    5.  
    6. Public Function FromBase64Array(sText As String) As Byte()
    7.     Const STR_BASE64_CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    8.     Static laPow2(0 To 30) As Long
    9.     Static laTable()       As Long
    10.     Dim baInput()       As Byte
    11.     Dim lIdx            As Long
    12.     Dim lCh             As Long
    13.     Dim baOutput()      As Byte
    14.     Dim lPtr            As Long
    15.     Dim lCarry          As Long
    16.    
    17.     On Error GoTo EH
    18.     '--- init decoding table
    19.     If laPow2(0) = 0 Then
    20.         For lIdx = 0 To UBound(laPow2)
    21.             laPow2(lIdx) = 2 ^ lIdx
    22.         Next
    23.         ReDim laTable(0 To &H3FF) As Long
    24.         For lIdx = 0 To UBound(laTable)
    25.             laTable(lIdx) = -1
    26.         Next
    27.         baInput = StrConv(STR_BASE64_CHARS, vbFromUnicode)
    28.         For lIdx = 0 To UBound(baInput)
    29.             lCh = baInput(lIdx)
    30.             laTable(lCh) = lIdx * laPow2(2)
    31.             laTable(&H100 + lCh) = (lIdx And &H30) \ laPow2(4) Or (lIdx And &HF) * laPow2(12)
    32.             laTable(&H200 + lCh) = (lIdx And &H3) * laPow2(22) Or (lIdx And &H3C) * laPow2(6)
    33.             laTable(&H300 + lCh) = lIdx * laPow2(16)
    34.         Next
    35.     End If
    36.     '--- figure out output size
    37.     baInput = StrConv(Replace(Replace(sText, vbCr, vbNullString), vbLf, vbNullString), vbFromUnicode)
    38.     If laTable(baInput(UBound(baInput))) >= 0 Then
    39.         lIdx = 1
    40.     ElseIf laTable(baInput(UBound(baInput) - 1)) >= 0 Then
    41.         lIdx = 2
    42.     Else
    43.         lIdx = 3
    44.     End If
    45.     ReDim baOutput(0 To (Len(sText) \ 4) * 3 - lIdx) As Byte
    46.     '--- decode loop
    47.     lPtr = VarPtr(baOutput(0))
    48.     For lIdx = 0 To UBound(baInput) - 3 Step 4
    49.         lCh = laTable(baInput(lIdx + 0)) _
    50.             Or laTable(&H100 + baInput(lIdx + 1)) _
    51.             Or laTable(&H200 + baInput(lIdx + 2)) _
    52.             Or laTable(&H300 + baInput(lIdx + 3))
    53.         If lCh < 0 Then
    54.             Exit For
    55.         End If
    56.         Call CopyMemory(ByVal lPtr, lCh, 3)
    57.         lPtr = (lPtr Xor &H80000000) + 3 Xor &H80000000
    58.     Next
    59.     lPtr = UnsignedDiff(VarPtr(baOutput(0)), lPtr)
    60.     '-- handle trailing 4 chars (or input error)
    61.     If lIdx <= UBound(baInput) Then
    62.         lCh = laTable(baInput(lIdx + 0))
    63.         Debug.Assert lCh >= 0 '--- input error
    64.         If lCh < 0 Then
    65.             GoTo QH
    66.         End If
    67.         lCarry = lCh
    68.         lCh = laTable(baInput(lIdx + 1))
    69.         Debug.Assert lCh >= 0 '--- input error
    70.         If lCh < 0 Then
    71.             GoTo QH
    72.         End If
    73.         baOutput(lPtr + 0) = (lCarry Or lCh \ laPow2(6)) And &HFF
    74.         lCarry = lCh * laPow2(2)
    75.         lCh = laTable(baInput(lIdx + 2))
    76.         If lCh < 0 Then
    77.             lPtr = lPtr + 1
    78.             GoTo QH
    79.         End If
    80.         baOutput(lPtr + 1) = (lCarry Or lCh \ laPow2(4)) And &HFF
    81.         lCarry = lCh * laPow2(4)
    82.         lCh = laTable(baInput(lIdx + 3))
    83.         If lCh < 0 Then
    84.             lPtr = lPtr + 2
    85.             GoTo QH
    86.         End If
    87.         Debug.Assert lCh < 0 '--- error in decoding tables
    88.         baOutput(lPtr + 2) = (lCarry Or lCh \ laPow2(2)) And &HFF
    89.         lPtr = lPtr + 3
    90.     End If
    91. QH:
    92.     '--- will redim only on input error
    93.     If UBound(baOutput) <> lPtr - 1 Then
    94.         ReDim Preserve baOutput(0 To lPtr - 1) As Byte
    95.     End If
    96.     FromBase64Array = baOutput
    97.     Exit Function
    98. EH:
    99.     Debug.Print Err.Description
    100. End Function
    101.  
    102. Private Function UnsignedDiff(ByVal lUnsignedPtr1 As Long, ByVal lUnsignedPtr2 As Long) As Long
    103.     '--- note: retval is *signed* offset b/n *unsigned* ptr1 and *unsigned* ptr2 w/o overflow in LARGEADDRESSAWARE processes
    104.     If (lUnsignedPtr1 And &H80000000) <> (lUnsignedPtr2 And &H80000000) Then
    105.         UnsignedDiff = (lUnsignedPtr2 - (lUnsignedPtr1 Xor &H80000000)) Xor &H80000000
    106.     Else
    107.         UnsignedDiff = lUnsignedPtr2 - lUnsignedPtr1
    108.     End If
    109. End Function
    And here is the much shorter API based impl w/ a single call to CryptStringToBinary (not twice)
    thinBasic Code:
    1. ' Attribute VB_Name = "mdApiFromBase64Array"
    2. Option Explicit
    3.  
    4. '--- for CryptStringToBinary
    5. Private Const CRYPT_STRING_BASE64           As Long = 1
    6.  
    7. Private Declare Function CryptStringToBinary Lib "crypt32" Alias "CryptStringToBinaryW" (ByVal pszString As Long, ByVal cchString As Long, ByVal dwFlags As Long, ByVal pbBinary As Long, ByRef pcbBinary As Long, ByRef pdwSkip As Long, ByRef pdwFlags As Long) As Long
    8.  
    9. Public Function ApiFromBase64Array(sText As String) As Byte()
    10.     Dim lSize           As Long
    11.     Dim dwDummy         As Long
    12.     Dim baOutput()      As Byte
    13.    
    14.     lSize = Len(sText) + 1
    15.     ReDim baOutput(0 To lSize - 1) As Byte
    16.     Call CryptStringToBinary(StrPtr(sText), Len(sText), CRYPT_STRING_BASE64, VarPtr(baOutput(0)), lSize, 0, dwDummy)
    17.     If lSize > 0 Then
    18.         ReDim Preserve baOutput(0 To lSize - 1) As Byte
    19.         ApiFromBase64Array = baOutput
    20.     Else
    21.         ApiFromBase64Array = vbNullString
    22.     End If
    23. End Function
    cheers,
    </wqw>

  6. #6
    Addicted Member
    Join Date
    Sep 2015
    Posts
    174

    Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by wqweto View Post
    @labmany: If you pinched the Decode64 function from VB - Fast Base64 Encoding and Decoding thread why did you choose the slower and more bloated pure VB6 implementation that returns (inconvenient) string that has to be treated w/ StrConv before saving to a binary BMP file?

    FYI, here is the shorter (and faster, and LAA) FromBase64Array function from the same thread
    thinBasic Code:
    1. ' Attribute VB_Name = "mdFromBase64Array"
    2. Option Explicit
    3.  
    4. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    5.  
    6. Public Function FromBase64Array(sText As String) As Byte()
    7.     Const STR_BASE64_CHARS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    8.     Static laPow2(0 To 30) As Long
    9.     Static laTable()       As Long
    10.     Dim baInput()       As Byte
    11.     Dim lIdx            As Long
    12.     Dim lCh             As Long
    13.     Dim baOutput()      As Byte
    14.     Dim lPtr            As Long
    15.     Dim lCarry          As Long
    16.    
    17.     On Error GoTo EH
    18.     '--- init decoding table
    19.     If laPow2(0) = 0 Then
    20.         For lIdx = 0 To UBound(laPow2)
    21.             laPow2(lIdx) = 2 ^ lIdx
    22.         Next
    23.         ReDim laTable(0 To &H3FF) As Long
    24.         For lIdx = 0 To UBound(laTable)
    25.             laTable(lIdx) = -1
    26.         Next
    27.         baInput = StrConv(STR_BASE64_CHARS, vbFromUnicode)
    28.         For lIdx = 0 To UBound(baInput)
    29.             lCh = baInput(lIdx)
    30.             laTable(lCh) = lIdx * laPow2(2)
    31.             laTable(&H100 + lCh) = (lIdx And &H30) \ laPow2(4) Or (lIdx And &HF) * laPow2(12)
    32.             laTable(&H200 + lCh) = (lIdx And &H3) * laPow2(22) Or (lIdx And &H3C) * laPow2(6)
    33.             laTable(&H300 + lCh) = lIdx * laPow2(16)
    34.         Next
    35.     End If
    36.     '--- figure out output size
    37.     baInput = StrConv(Replace(Replace(sText, vbCr, vbNullString), vbLf, vbNullString), vbFromUnicode)
    38.     If laTable(baInput(UBound(baInput))) >= 0 Then
    39.         lIdx = 1
    40.     ElseIf laTable(baInput(UBound(baInput) - 1)) >= 0 Then
    41.         lIdx = 2
    42.     Else
    43.         lIdx = 3
    44.     End If
    45.     ReDim baOutput(0 To (Len(sText) \ 4) * 3 - lIdx) As Byte
    46.     '--- decode loop
    47.     lPtr = VarPtr(baOutput(0))
    48.     For lIdx = 0 To UBound(baInput) - 3 Step 4
    49.         lCh = laTable(baInput(lIdx + 0)) _
    50.             Or laTable(&H100 + baInput(lIdx + 1)) _
    51.             Or laTable(&H200 + baInput(lIdx + 2)) _
    52.             Or laTable(&H300 + baInput(lIdx + 3))
    53.         If lCh < 0 Then
    54.             Exit For
    55.         End If
    56.         Call CopyMemory(ByVal lPtr, lCh, 3)
    57.         lPtr = (lPtr Xor &H80000000) + 3 Xor &H80000000
    58.     Next
    59.     lPtr = UnsignedDiff(VarPtr(baOutput(0)), lPtr)
    60.     '-- handle trailing 4 chars (or input error)
    61.     If lIdx <= UBound(baInput) Then
    62.         lCh = laTable(baInput(lIdx + 0))
    63.         Debug.Assert lCh >= 0 '--- input error
    64.         If lCh < 0 Then
    65.             GoTo QH
    66.         End If
    67.         lCarry = lCh
    68.         lCh = laTable(baInput(lIdx + 1))
    69.         Debug.Assert lCh >= 0 '--- input error
    70.         If lCh < 0 Then
    71.             GoTo QH
    72.         End If
    73.         baOutput(lPtr + 0) = (lCarry Or lCh \ laPow2(6)) And &HFF
    74.         lCarry = lCh * laPow2(2)
    75.         lCh = laTable(baInput(lIdx + 2))
    76.         If lCh < 0 Then
    77.             lPtr = lPtr + 1
    78.             GoTo QH
    79.         End If
    80.         baOutput(lPtr + 1) = (lCarry Or lCh \ laPow2(4)) And &HFF
    81.         lCarry = lCh * laPow2(4)
    82.         lCh = laTable(baInput(lIdx + 3))
    83.         If lCh < 0 Then
    84.             lPtr = lPtr + 2
    85.             GoTo QH
    86.         End If
    87.         Debug.Assert lCh < 0 '--- error in decoding tables
    88.         baOutput(lPtr + 2) = (lCarry Or lCh \ laPow2(2)) And &HFF
    89.         lPtr = lPtr + 3
    90.     End If
    91. QH:
    92.     '--- will redim only on input error
    93.     If UBound(baOutput) <> lPtr - 1 Then
    94.         ReDim Preserve baOutput(0 To lPtr - 1) As Byte
    95.     End If
    96.     FromBase64Array = baOutput
    97.     Exit Function
    98. EH:
    99.     Debug.Print Err.Description
    100. End Function
    101.  
    102. Private Function UnsignedDiff(ByVal lUnsignedPtr1 As Long, ByVal lUnsignedPtr2 As Long) As Long
    103.     '--- note: retval is *signed* offset b/n *unsigned* ptr1 and *unsigned* ptr2 w/o overflow in LARGEADDRESSAWARE processes
    104.     If (lUnsignedPtr1 And &H80000000) <> (lUnsignedPtr2 And &H80000000) Then
    105.         UnsignedDiff = (lUnsignedPtr2 - (lUnsignedPtr1 Xor &H80000000)) Xor &H80000000
    106.     Else
    107.         UnsignedDiff = lUnsignedPtr2 - lUnsignedPtr1
    108.     End If
    109. End Function
    And here is the much shorter API based impl w/ a single call to CryptStringToBinary (not twice)
    thinBasic Code:
    1. ' Attribute VB_Name = "mdApiFromBase64Array"
    2. Option Explicit
    3.  
    4. '--- for CryptStringToBinary
    5. Private Const CRYPT_STRING_BASE64           As Long = 1
    6.  
    7. Private Declare Function CryptStringToBinary Lib "crypt32" Alias "CryptStringToBinaryW" (ByVal pszString As Long, ByVal cchString As Long, ByVal dwFlags As Long, ByVal pbBinary As Long, ByRef pcbBinary As Long, ByRef pdwSkip As Long, ByRef pdwFlags As Long) As Long
    8.  
    9. Public Function ApiFromBase64Array(sText As String) As Byte()
    10.     Dim lSize           As Long
    11.     Dim dwDummy         As Long
    12.     Dim baOutput()      As Byte
    13.    
    14.     lSize = Len(sText) + 1
    15.     ReDim baOutput(0 To lSize - 1) As Byte
    16.     Call CryptStringToBinary(StrPtr(sText), Len(sText), CRYPT_STRING_BASE64, VarPtr(baOutput(0)), lSize, 0, dwDummy)
    17.     If lSize > 0 Then
    18.         ReDim Preserve baOutput(0 To lSize - 1) As Byte
    19.         ApiFromBase64Array = baOutput
    20.     Else
    21.         ApiFromBase64Array = vbNullString
    22.     End If
    23. End Function
    cheers,
    </wqw>
    Thanks for the tip, I'll use that

  7. #7
    Addicted Member
    Join Date
    Sep 2015
    Posts
    174

    Re: vb 6.0 convert base64 image data into .bmp image

    Sorry, double post!

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,405

    Re: vb 6.0 convert base64 image data into .bmp image

    FWIW, here a Variant for RC5-Users:

    The code should work when pasted into on an empty Form (as long as a vbRichClient5-reference was checked into the Project) -
    then it downloads a Base64-Image-Text-(String) via Web-Request - and decodes+visualizes in the Form.Picture directly.

    Code:
    Option Explicit
    
    Private WithEvents DL As cDownloads
    
    Private Sub Form_Load()
      Set DL = New_c.Downloads
          DL.Download "http://vbRichClient.com/Downloads/Base64Image.txt"
    End Sub
    
    Private Sub DL_DownloadComplete(DownloadObj As cDownload, ByVal ErrNum&, ErrString As String)
      If ErrNum Then MsgBox ErrString Else DecodeB64Img Cairo.ToBSTR(DownloadObj.GetContentData)
    End Sub
    
    Private Sub DecodeB64Img(sB64 As String)
      Dim B() As Byte: B = New_c.Crypt.Base64Dec(sB64, True)'decode sB64
      
      With Cairo.ImageList.AddImage("", B) '<-can load most Img-B-Arrays
    
        Set Picture = .Picture 'convert the Srf-content to VB-StdPicture
       '.WriteContentToPngFile "c:\temp\B64Dec.png" 'or write it to disk
    
      End With
    End Sub
    HTH

    Olaf

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,646

    Re: vb 6.0 convert base64 image data into .bmp image

    Since the raw image is already in BMP format you can just convert Base64 text to bytes and write them to a file if compression isn't important.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,646

    Re: vb 6.0 convert base64 image data into .bmp image

    References to:

    Microsoft ActiveX Data Objects 2.5 Library
    Microsoft CDO for Windows 2000 Library

    Code:
        With New CDO.Message
            With .BodyPart
                .ContentMediaType = "image/bmp"
                .ContentTransferEncoding = "base64"
                With .GetEncodedContentStream
                    .LoadFromFile "image data base 64.txt"
                    .Flush
                End With
                With .GetDecodedContentStream
                    .SaveToFile "image.bmp", adSaveCreateOverWrite
                End With
            End With
        End With

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    4

    Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by labmany View Post
    Name:  WBC.png
Views: 104
Size:  4.7 KB
    This is a sample to convert Base64 into a bitmap.

    May I ask what hematology analyzer is this?!


    P.S :
    * The Base64 Decoding function was freely available on the Internet
    ** The function for saving byte array into a bitmap was kindly provided by Olaf Schmidt
    Thanks for the help @labmany. i will try this code.The analyzer is Erba H360

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,464

    Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by rahuls.8333 View Post
    I have requirement to create .bmp or .png or .jpeg image from data received from a source in base64 format. i want to convert this text data(base 64) into a .bmp image file. our application is developed in vb 6.0

    Rahul.
    FYI: Converting PNG to Bitmap may lose any PNG transparency depending on bitmap format saved to. Even if saved to a bitmap format that will honor transparency (2 formats), any app reading the file may not properly display transparency since transparency in bitmaps isn't typical.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,646

    Re: vb 6.0 convert base64 image data into .bmp image

    The raw data is a simple 24bpp BMP.

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,464

    Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by dilettante View Post
    The raw data is a simple 24bpp BMP.
    That sample, but the original post can be interpreted as PNG & JPG sources (or destinations?)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,646

    Re: vb 6.0 convert base64 image data into .bmp image

    I suppose, but then it may as likely contain something nasty (PCX, TARGA?). Or even a raw bitmap's bits. Or some vector format, metafile format, or who knows what?

    Here's something else you probably won't see many places:

    Code:
        Dim Size As Long
        Dim RS As ADODB.Recordset
        Dim FMT As StdFormat.StdDataFormat
    
        With New CDO.Message
            With .BodyPart
                .ContentMediaType = "image/bmp"
                .ContentTransferEncoding = "base64"
                With .GetEncodedContentStream
                    .LoadFromFile "image data base 64.txt"
                    .Flush
                End With
                With .GetDecodedContentStream
                    .SaveToFile "image.bmp", adSaveCreateOverWrite
                    'Get a StdPicture through devious means and display it:
                    Size = .Size
                    Set RS = New ADODB.Recordset
                    With RS
                        .Fields.Append "Picture", adLongVarBinary, Size
                        .Open
                        .AddNew
                    End With
                    RS.Fields("Picture").Value = .Read(adReadAll)
                    Set FMT = New StdFormat.StdDataFormat
                    FMT.Type = fmtPicture
                    With RS
                        Set .Fields("Picture").DataFormat = FMT
                        Set Picture = .Fields("Picture").Value
                        .Close
                    End With
                End With
            End With
        End With
    I suspect it will handle any image file format that VB's LoadPicture() can since it returns a Picture type object (a StdPicture's IPictureDisp interface?).

  16. #16

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    4

    Thumbs up Re: vb 6.0 convert base64 image data into .bmp image

    Quote Originally Posted by dilettante View Post
    References to:

    Microsoft ActiveX Data Objects 2.5 Library
    Microsoft CDO for Windows 2000 Library

    Code:
        With New CDO.Message
            With .BodyPart
                .ContentMediaType = "image/bmp"
                .ContentTransferEncoding = "base64"
                With .GetEncodedContentStream
                    .LoadFromFile "image data base 64.txt"
                    .Flush
                End With
                With .GetDecodedContentStream
                    .SaveToFile "image.bmp", adSaveCreateOverWrite
                End With
            End With
        End With

    works perfectly fine for my requirement!!!!, thanx a ton

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width