FolderItem to open pic files and use them in WebImageViewer?

I am trying to open a PNG file to display into a WebImageViewer.

I’ve tried to use FolderItem to no avail.

How would I resolve this? Do I have to manually add all the pics to my project? There are seventeen choices of pics and I want the user’s five chosen pics to show up in a row of WebImageViewers.

You could try

Var pic As New WebPicture

Var f As FolderItem = New FolderItem(<Path to file>)

Var b As BinaryStream = BinaryStream.Open(f)

pic.Data = b.Read(b.Length)

b.Close

me.Picture = pic

This is in the Shown Event Handler of the ImageViewer.

1 Like

WebFile has an Open shared method that allows you to pass a FolderItem and receive a WebFile, which you can then use in your WebImageViewer.

1 Like

I tried the following code in an attempt to get this to work:

Var f As FolderItem = New FolderItem("1.png") // Get the file using a FolderItem
If f <> Nil And f.Exists Then
// Convert the FolderItem to a WebFile
App.MyFile = WebFile.Open(f) // MyFile is a property on the App object
App.MyFile.MIMEType = "PNG"
Me.Picture = App.MyFile
End If

Not sure how to get WebFile to work, as there is no sample code on how to convert a WebFile to a WebPicture.

This works beautifully, thanks!

[EDITED] — for this solution to work - I used a Build Step whereby the files and folders are COPIED over into where I intend to draw the pic from.

For NESTED folder items - the following code is what I used, in conjunction with a Build Step to copy over the folder containing my pics:

Var pic As New WebPicture

Var f As FolderItem = New FolderItem("")
f = f.Child("0").Child("1.png")

Var b As BinaryStream = BinaryStream.Open(f)

pic.Data = b.Read(b.Length)

b.Close

me.Picture = pic

Hopefully this adds a layer of context to the original solution.
Thanks again @Wayne_Golding

You can assign the URL property on the WebFile to the URL property of the WebImageView. Be sure to keep the WebFile in scope.

1 Like

I think I am just going to use the solution as-is, as there are literally hundreds of pictures that are pieces of this gameboard I am building.