New project: one window containg a canvas and an imagewell + pict filetypes
In the canvas and in the imageWell open event handler I have:
me.AcceptFileDrop SupportedImageFormats.all
and In the canvas and in the imageWell dropobject event handler I have
If Obj.PictureAvailable Then
me.Backdrop = obj.Picture
end if
and
If Obj.PictureAvailable Then
me.image = obj.Picture
end if
But while dropping a .png picturefile into the imagewell works, dropping the same file into the canvas does not work.
Tried removing the imagewell and leaving only the canvas: it still doesn’t work.
And of course, I cannot have it work in existing projects.
BTW: I cannot have it work even dropping onto a window…
Suggestions welcome. Thanks.
Xojo 2021r2.1 and Xojo 2024r2.4
Last Sonoma
Carlo Rubini:
Obj.PictureAvailable
This is when you drop an image from a software. For File drop, Use Obj.FolderItemAvailable instead.
It tooks me sometimes to understand why it does not works here !
If Obj.FolderItemAvailable Then
me.Backdrop = obj.Picture
end if
Nothing else to change.
Done it: in the debugger now I see that Obj.FolderItemAvailable is executed and the next line “me.Backdrop = obj.Picture” too is executed; yet no picture shows up in the canvas.
Thanks for answering.
No it doesn’t
Did a quick test in the DropObject Canvas event with:
If obj.FolderItemAvailable Then
Var p As New FolderItem(obj.FolderItem.NativePath)
If p <> Nil Then
Me.backdrop = Picture.Open(p)
End If
End If
Don’t forget to put in the Canvas opening event also:
Me.AcceptFileDrop("image/png")
Me.AcceptFileDrop("image/jpeg")
Me.AcceptFileDrop("image/tiff")
Though interestingly this accepts then also .svg files (o;
I used:
Sub Open()
Var pngType As New FileType pngType.Name = "image/png" pngType.Extensions = ".png"
// Enable Drop an File above the Canvas
Canvas1.AcceptFileDrop(pngType)
End Sub
Still doesn’t explain when you just enable PNG file drops, it allows to drop every picture format and shows it.
It worked, so was the answer to OP.
To restrain the non wanted file types, you have to check them in the DropObject Event.
That had changed to this some years ago.
Sorry Emile, here it did not work, while Richard snipped worked.
But why does an imageWell work straight away?
If Obj.PictureAvailable Then
me.image = obj.Picture
end if
Try to drop a text (or bin or whatever is not an image file) onto your canvas / ImageWell and see what happens…
Remember: standard users are capable of eveything even dropping a text file onto a Canvas… or depends on your code.