Retrieving a picture

Good morning,
I know this is Xojo 101 but how to I retrieve a picture.

I have a sqlite table and one of the fields is the name of the picture. Now I want to retrieve that picture from a folder and put it in a canvas. I got this code but I get a compile error because I am telling that f is a string instead of a picture.

Dim currentFolder As FolderItem
currentFolder = GetFolderItem("").child("fotos")

Dim f as Picture
msgbox currentFolder.name

f = currentFolder.name + rs.Column("pic1").StringValue
canvas2.Backdrop = f

Take a look at the Foldertem entry in the LR.

something like below will work:

canvas2.Backdrop = currentFolder.Child(rs.Column(pic1").StringValue)

Thanks Emile,
I get a compiler error “Expected picture but got folderitem”

You need to read the data of a folderitem into a binarystream. Then you use FromData to make a picture.

Dim currentFolder As FolderItem = GetFolderItem("").child("fotos")
dim PictureFolderitem as Folderitem = currentFolder.child(rs.Column("pic1").StringValue)
dim b as BinaryStream = Binarystream.Open(PictureFolderitem)
dim data as String = b.read(b.length)
canvas2.Backdrop = Picture.FromData(data)

Code not tested. Error handling omitted.

Thank You Beatrix,
That worked! The binary was what I was missing.
Allen

1 Like

i understood you have a filename in database.
just use this method with a folderitem and it return a picture.
https://documentation.xojo.com/api/graphics/picture.html#picture-open

1 Like

Picture.Open is what I use, I was not aware that you could open it as a binary stream to do the same thing. But Picture.Open seems to be much easier to read the code.