Hi @Theodosis ,
The following example is to load pictures from a URL, then reset the resolution, and finally display one of them in picture box.
Here's the code you can refer to.
Private newBitmap As Bitmap
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim imgLst As List(Of Bitmap) = Await GetImagesFromURL("image url")
newBitmap = New Bitmap(imgLst(0))
' Set bitmap resolution
newBitmap.SetResolution(50, 50)
PictureBox1.Image = newBitmap
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
PictureBox1.Image = Nothing
newBitmap.Dispose()
End Sub
Private Async Function GetImagesFromURL(url As String) As Task(Of List(Of Bitmap))
Dim images = New List(Of Bitmap)()
Using client = New HttpClient()
Dim response = Await client.GetAsync(url)
If response IsNot Nothing AndAlso response.StatusCode = HttpStatusCode.OK Then
Using stream = Await response.Content.ReadAsStreamAsync()
Dim memStream = New MemoryStream()
Await stream.CopyToAsync(memStream)
memStream.Position = 0
images.Add(New Bitmap(memStream))
End Using
End If
End Using
Return images
End Function
Hope it could be helpful.
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.