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.
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.
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.
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
Var fiImageFile As FolderItem
Var oImage As Picture
Var oSizedImage As Picture
fiImageFile = NEW FolderItem("c:\Image\AE01-0500.jpg")
oImage = Picture.Open(fiImageFile)
' If the image size is greater than the allowed imgThumbImage size then resize the image to fit (imgThumbImage is my WebImageViewer object)
If ((oImage.Width > imgThumbImage.Width) Or (oImage.Height > imgThumbImage.Height)) Then
oSizedImage = NEW Picture(imgThumbImage.Width, imgThumbImage.Height, 32)
oSizedImage.Graphics.DrawPicture(oImage, 0, 0, imgThumbImage.Width, imgThumbImage.Height, 0, 0, oImage.Width, oImage.Height)
imgThumbImage.Picture = oSizedImage
Else
imgThumbImage.Picture = oImage
End If