xmxmxm22 2023-05-23 00:30 采纳率: 0%
浏览 27

vba 窗体图片加载能否是网络图片

图片地址可否是网络图片地址?
在窗体图片中,image1.picture=loadpicture("图片地址"),这个地址可否是网络地址,例如"https://……/20180108/1515381330183/2e872c81464e22df0463e67f661a0303.jpg",
为什么老是报错"76" :路径为找到

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-05-23 04:42
    关注

    不能这么直接用,得先下载了再显示

    可以用下面的代码

    Private Const scUserAgent = "BF"
    Private Const INTERNET_OPEN_TYPE_DIRECT = 1
    Private Const INTERNET_OPEN_TYPE_PROXY = 3
    Private Const INTERNET_FLAG_RELOAD = &H80000000
    
    Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
    Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    Function DownFile(ByVal strURL As String, ByVal strPath As String) As Boolean
    On Error GoTo ERR:
        Dim hOpen As Long, hFile As Long, sBuffer() As Byte, Ret As Long
    
        hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
        If hOpen = 0 Then DownFile = False: Exit Function
        hFile = InternetOpenUrl(hOpen, strURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
        If hFile = 0 Then DownFile = False: Exit Function
       
        If Dir(strPath) <> "" Then
            If (MsgBox("目标文件存在,是否覆盖?", vbYesNo)) = vbYes Then
                     Kill strPath
                 Else
                     DownFile = False
                     Exit Function
            End If
        End If
        Open strPath For Binary As #1
        ReDim sBuffer(999)
        Do
        InternetReadFile hFile, sBuffer(0), 1000, Ret
        If Ret <> 0 Then
             If Ret < 1000 Then ReDim Preserve sBuffer(Ret - 1)
             Put #1, , sBuffer
           Else
             Exit Do
        End If
        DoEvents
        Loop
       
        Close #1
       
        InternetCloseHandle hFile
        InternetCloseHandle hOpen
       
        DownFile = True
        Exit Function
       
    ERR:
        DownFile = False
    End Function
    

    DownFile "http://www.abc.com/你的图片.jpg","c:\你的图片.jpg"
    Picture1.Picture = LoadPicture("C:\你的图片.jpg")

    评论

报告相同问题?

问题事件

  • 创建了问题 5月23日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度