Imports System.Net
Imports System.IO
Module Module1
Sub Main()
DownloadImage("https://img2.baidu.com/it/u=2777280900,1082757912&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=500")
End Sub
Sub DownloadImage(ByVal imageUrl As String)
Try
Dim webClient As New WebClient()
Dim imageData As Byte() = webClient.DownloadData(imageUrl)
Dim filePath As String = "C:\Users\Administrator\Documents\新建文件夹\2.jpg" ' 替换为你想要保存的路径和文件名
Using fs As New FileStream(filePath, FileMode.Create)
fs.Write(imageData, 0, imageData.Length)
End Using
Console.WriteLine("Image downloaded successfully.")
Catch ex As Exception
Console.WriteLine("Error occurred: " & ex.Message)
End Try
End Sub
End Module