Scale a JPG into a WebImageView

I have a JPG file in a web server.
I want to show it in a WebImageView in a way that fits inside the WebImageView.
Any one have a snippet for doing this ?

1 Like

Here you go.

Public Sub DownloadAndDisplayIMG(URL as String, TheFrame as WebImageView)
  Dim socket As New HTTPSocket
  Dim data As String = socket.Get(URL, 5) 
  If socket.HTTPStatusCode = 200 Then 
    Dim p As Picture = Picture.FromData(data)
    If p <> Nil Then
      TheFrame.Picture = ScaleImage(p, TheFrame.Width, TheFrame.Height)
      MsgBox("Not a picture.")
    End If
    MsgBox("HTTP Status: " + Str(socket.HTTPStatusCode))
  End If
End Sub

Public Function ScaleImage(p as Picture, maxWidth as Integer, maxHeight as Integer) as Picture
  If p <> Nil Then
    Dim ratio As Double = min(maxHeight / p.height, maxWidth / p.width)
    Dim newPic As New Picture(p.width * ratio, p.height * ratio), 0, 0, newPic.width, newPic.height, 0, 0, p.width, p.height)
    Return newPic
  End If
End Function
1 Like

Thanks @RomanV.