如何在文件中将图像PNG从文件加载到VBA中的图像使用表单

时间:2019-07-05 04:32:59

标签: vba image png bmp

无法在VBA中加载png图像

Private Sub btnCreate_Click()

Dim readFile
If (txtData.text = "") Then
    MsgBox "Please Enter Data"
Else
    Dim objWinHttp As Object
    Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
    Dim URL As String
    URL = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + txtData.text + "&choe=UTF-8"
    objWinHttp.Open "GET", URL, False
    objWinHttp.send ""
    SaveBinaryData "E:\qr.png", objWinHttp.responseBody
    Image1.Picture = LoadPicture("E:\qr.png")

End If
End Sub

功能保存BinaryData

Function SaveBinaryData(FileName, Data)

    Const adTypeText = 1
    Const adSaveCreateOverWrite = 2

    Dim BinaryStream
    Set BinaryStream = CreateObject("ADODB.Stream")

    BinaryStream.Type = adTypeText

    BinaryStream.Open
    BinaryStream.Write Data


    BinaryStream.saveToFile FileName, adSaveCreateOverWrite
    BinaryStream.Close

End Function

错误“无效图片”

谢谢大家阅读

0 个答案:

没有答案