Draw Picture from URL

I am attempting to draw a web picture from a URL stored in my database that on login the URL is saved to Session String Parameter.

Logically in my head this code makes sense. But I get nothing. Not even the MsgBox on fail.

Help?

dim p as new picture(150,150) 
Dim picFolder As New FolderItem(Session.Picture)

If picFolder<> Nil And picFolder.Exists Then
  Dim pic As New WebPicture(picFolder)
  p.graphics.drawpicture(pic,0,0,p.Width,p.Height,0,0,pic.Width,pic.Height)
  Me.Picture = p
Else
  MsgBox "Nope"
End If

If you debug the application, what’s the value of Session.Picture? Does it looks like a valid file path?

MsgBox "Picture Path: " + Session.Picture

Dim picFolder As New FolderItem(Session.Picture)

This line really should have given you an UnsupportedFormatException when you passed it a remote URL and not a file path: FolderItem — Xojo documentation

There is no way to create a WebPicture from a URL, so to draw a remote image inside a WebCanvas you would need to download the image to the server. You can however, display the URL in a WebImageViewer: WebImageViewer — Xojo documentation

2 Likes

If I got this route of using URL in WebImage Viewer. Is there a way to resize it?

It does not appear to be possible within the framework. You could file a ticket requesting the feature.

It may be possible with ExecuteJavascript but the inner-div of an image viewer doesn’t have an ID, so it’s going to require a little bit of poking around to write something. The core of the issue is we need to set the inner-div CSS to use background-size: contain.

It might be as simple as using the firstChild but you may need to do it on every image load. @Ricardo_Cruz might have some useful insight. I can come back to this later, but during the day I pop onto the forum while I’m waiting on Xojo (and don’t have tons of time to play).

I think this should work:

Me.Style.Value("background-size") = "contain"

Edit: I’ve just found this old case, Issue #39829. I can’t see the posted images anymore, but it looks like that feature request should be more or less what you’ve mentioned @Tim_Parnell .

2 Likes

I just wanted to check back in and report that this style method works. It would be cool to see a framework option to do this.

3 Likes

IMO that should be the default whenever displaying an image using the URL parameter. It is the only way to correctly display a HiDPI image.
But a framework option would be great.

2 Likes

Can we upvote that case to add the framework option (as Tim said)? or a new case is needed?

I think that one is fine Alberto :+1:

1 Like