Unable to open picture with Canvas or ImageWell

Hello Everyone,

I am unable to open a picture (cam.jpg) on the Raspberry Pi, and the program works on Windows. The picture is placed on the desktop on both computers and on the Pi there is the following error:

The picture cam.jpg is just a screen grab. A listbox has been added to track the errors and the path is shown on windows and “File is nil” is shown on Raspberry Pi.

Here is the code which works on Windows but not on the Pi.

[code] //Works on Windows
//Does not work on Raspberry Pi 2 B
Dim MyFile as FolderItem = SpecialFolder.Desktop.Child(“cam.jpg”)

If MyFile <> Nil then
If MyFile.Exists then
Canvas1.Backdrop = Picture.Open(MyFile)
ImageWell1.Image = Picture.Open(MyFile)
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If
Listbox1.AddRow MyFile.NativePath
[/code]

Here is a link to the file: Picture11-01

Is there something that I am doing wrong or incorrectly assuming on the Raspberry Pi?

Thanks for your help.

The plot thickens… :slight_smile:

The modified file opening works in an Open Dialog in both Windows and Pi, and gives the following error in the terminal

quote: Gtk-warning **: Attempting to store changes into ‘/root/.local/share/recently-used.xbel’, but failed: Failed to create file ‘/root/.local/share/recently-used.xbel.JSQ8FY’ No such file or directory
(Example11-1:1564): Gtk-warning **: Attempting to set the permissions of ‘/root/.local/share/recently-used/xbel’, but failed: No such file or directory
[/quote]

Below is the screen grab of this error.

Here is the Xojo file download.
Example11-1a

And here is the running code:

[code] //Works on Windows
//Does not work on Raspberry Pi 2 B
Dim MyFile as New FolderItem

Dim dlg as OpenDialog
dlg = new OpenDialog
MyFile = dlg.ShowModal

If MyFile <> Nil then
If MyFile.Exists then
Canvas1.Backdrop = Picture.Open(MyFile)
ImageWell1.Image = Picture.Open(MyFile)
Listbox1.AddRow MyFile.NativePath
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If
[/code]

I am taking a wild guess here… is it possible that instead of Pi looking for the file at:
/home/pi/Desktop/cam.jpg
Xojo is instead attempting to look for the file in
/home/pi/desktop/cam.jpg (the lowercase d in Desktop?).

Thanks :slight_smile:

It’s also important to check if Picture.Open returned Nil. This can happen if the platform can’t open the file.

Since JPEG files have been involved in some expensive licensing battles, it may be that they’re not supported at all. Try using a PNG file instead.

[quote=261228:@Eugene Dakin]
I am taking a wild guess here… is it possible that instead of Pi looking for the file at:
/home/pi/Desktop/cam.jpg
Xojo is instead attempting to look for the file in
/home/pi/desktop/cam.jpg (the lowercase d in Desktop?).[/quote]
You can check that by logging Myfile.NativePath just after you assign the variable.

…and FWIW, in your second example you don’t need to declare MyFile as a “New Folderitem” as OpenDialog returns one to you.

Thanks for your helpful comments Greg. After trying out these suggestions, it appears that this command returns a NilObjectException Error:

Dim MyFile as FolderItem = SpecialFolder.Desktop.Child("cam.png")

… and this opens the file, displays the picture, and shows the terminal Gtk-warnings:

[code]Dim MyFile as New FolderItem

Dim dlg as OpenDialog
dlg = new OpenDialog
MyFile = dlg.ShowModal[/code]

Here is the code which shows “Did it make it here?” and “File is nil”:

[code] //Works on Windows
//Does not work on Raspberry Pi 2 B
Dim p as Picture
Dim MyFile as FolderItem = SpecialFolder.Desktop.Child(“cam.png”)
Listbox1.AddRow “Did it make it here?”

If MyFile <> Nil then
If MyFile.Exists then
p = Picture.Open(MyFile)
If p <> Nil then
Canvas1.Backdrop = p
ImageWell1.Image = p
Listbox1.AddRow MyFile.NativePath
Else
Listbox1.AddRow “p is nil”
End If
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If
[/code]

Using an OpenDialog opens the file, shows the png file, and path at “/home/pi/Desktop/cam.png”, and shows the Gtk-warning messages in the terminal:

[code] //Works on Windows
//Does not work on Raspberry Pi 2 B
Dim p as Picture
Dim MyFile as FolderItem

Dim dlg as OpenDialog
dlg = new OpenDialog
MyFile = dlg.ShowModal
Listbox1.AddRow “Did it make it here?”

If MyFile <> Nil then
If MyFile.Exists then
p = Picture.Open(MyFile)
If p <> Nil then
Canvas1.Backdrop = p
ImageWell1.Image = p
Listbox1.AddRow MyFile.NativePath
Else
Listbox1.AddRow “p is nil”
End If
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If
[/code]

Thanks :slight_smile: I was trying anything to try and bypass this issue.

This works well in the OpenDialog method, and is nil with the Desktop.Child(“cam.png”) method.

Greg, thanks for your kind suggestions. Do you have any other helpful hints that I might have made an error when using the Desktop.Child method?

It sounds like SpecialFolder.Desktop is failing unfortunately. Have you tried any other SpecialFolder calls? Like SpecialFolder.UserHome? If that works, you could concat Desktop and cam.jpg.

It also might be worth logging the NativePath of SpecialFolder.Desktop on its own to see if it’s right and if it actually exists.

Hi Greg. I just tried SpecialFolder.UserHome.Child(“cam.png”) and received the message “Did it make it here?” and “File does not exist” with the code below. (Note: I did put the cam.png file in the /home/ directory)

The line ‘Listbox1.AddRow "SF.D = " + SpecialFolder.Desktop.NativePath’ was added, and the result was ‘SF.D = /root/Desktop’. This directory should probably be ‘/home//Desktop’

Here is the code:

[code]
Dim p as Picture
Dim MyFile as FolderItem = SpecialFolder.Home.Child(“cam.png”)
Listbox1.AddRow “Did it make it here?”

If MyFile <> Nil then
If MyFile.Exists then
p = Picture.Open(MyFile)
If p <> Nil then
Canvas1.Backdrop = p
Listbox1.AddRow MyFile.NativePath
Else
Listbox1.AddRow “p is nil”
End If
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If

Listbox1.AddRow "SF.D = " + SpecialFolder.Desktop.NativePath
[/code]

Thanks again for your thoughts.

Methinks Xojo should implement ExtraSpecialFolderYouCanWriteToWhenAllElseFails. :wink:

[quote=261591:@Eugene Dakin]Hi Greg. I just tried SpecialFolder.UserHome.Child(“cam.png”) and received the message “Did it make it here?” and “File does not exist” with the code below. (Note: I did put the cam.png file in the /home/ directory)

The line ‘Listbox1.AddRow "SF.D = " + SpecialFolder.Desktop.NativePath’ was added, and the result was ‘SF.D = /root/Desktop’. This directory should probably be ‘/home//Desktop’

Here is the code:

[code]
Dim p as Picture
Dim MyFile as FolderItem = SpecialFolder.Home.Child(“cam.png”)
Listbox1.AddRow “Did it make it here?”

If MyFile <> Nil then
If MyFile.Exists then
p = Picture.Open(MyFile)
If p <> Nil then
Canvas1.Backdrop = p
Listbox1.AddRow MyFile.NativePath
Else
Listbox1.AddRow “p is nil”
End If
Else
Listbox1.AddRow “File does not exist”
End If
Else
Listbox1.AddRow “File is nil”
End If

Listbox1.AddRow "SF.D = " + SpecialFolder.Desktop.NativePath
[/code]

Thanks again for your thoughts.[/quote]
Please file a bug report about that with your sample project.

The following feedback report has been created.

<https://xojo.com/issue/43565>

I am usually hesitant at filing feedback reports until I am pretty sure that it is a real issue. Thanks for your help!