Static Img_Nbr As Integer = 1
Var Img_FI As FolderItem
Var Img_Cnt As Integer
// Do nothing if no valid USA Folder
If pUSA_FI = Nil Then Return False
// Clears the present Contents
Me.Backdrop = Nil
// How many Images ?
Img_Cnt = pUSA_FI.Count
// To Avoid “File Not Found”
If Img_Nbr >= Img_Cnt Then
Img_Nbr = 1
End If
// Read the image number #…
If key = Chr(28) And Img_Nbr > 1 Then // Left Arrow
Img_Nbr = Img_Nbr - 1
'System.DebugLog "[28] Left Arrow"
ElseIf key = Chr(29) And Img_Nbr < Img_Cnt Then // Right Arrow
Img_Nbr = Img_Nbr + 1
'System.DebugLog "[29] Right Arrow"
ElseIf key = Chr(30) Then // Up Arrow
Img_Nbr = 1
'System.DebugLog "[30] Up Arrow"
ElseIf key = Chr(31) Then // Down Arrow
Img_Nbr = Img_Cnt
'System.DebugLog "[31] Down Arrow"
Else
'System.DebugLog "Unknow Key"
End If
// Get a Reference to the first image
Img_FI = pUSA_FI.Item(Img_Nbr)
// Load the first image
Var OffscreenPict As Picture
Var Image_Pict As Picture
Var Img_Width As Integer
Var Img_Height As Integer
Var ratio As Double
// Load the image
OffscreenPict = Picture.Open(Img_FI)
If OffscreenPict = Nil Then
MessageBox "An error occured" + EndOfLine + EndOfLine+_
"OffscreenPict is Nil."
Return False
End If
// Gets its size
Img_Width = OffscreenPict.Width
Img_Height= OffscreenPict.Height
// Create another Picture
Image_Pict = New Picture (Img_Width, Img_Height)
If Image_Pict = Nil Then
MessageBox "An error occured" + EndOfLine + EndOfLine+_
"Image_Pict is Nil."
Return False
End If
If Img_Width > Img_Height Then
ratio = Img_Width / Img_Height
Else
ratio = Img_Height / Img_Width
End If
// Resize the image to the Canvas boundaries
Image_Pict.Graphics.DrawPicture OffscreenPict, _
0,0, Img_Width/ratio,Img_Height/ratio, _
0,0, Img_Width,Img_Height
'0,0, Me.Width,Me.Height, _
// Clear the Image from the Memory
OffscreenPict = Nil
// Set the Canvas Size
Me.Width = Img_Width/ratio // Image_Pict.Width
Me.Height = Img_Height/ratio // Image_Pict.Height
Me.Refresh
// And display the image
Me.Backdrop = Image_Pict
// Display its file name
Name_USA.Text = Img_FI.Name
// I handled the Key press
Return True
I commented the DebugLog, but will remove them soon…
From your code ‘Img_FI’ is a FolderItem, could that be a non-valid Picture?
I guess that will make OffscreenPict Nil.
As you are showing a MessageBox with the “OffscreenPict is Nil.” warning, can you add the name or path of the FolderItem (Img_FI) so you can have more information on what is wrong?
Sometimes when the block of code is nested or large, the forum parser fails to provide color.
As is, yes. But this does not explain the behavior.
The test folders have been created on purpose (nothing inside previously) and when I had to remove some not relevant images, I put them in a Folder out from the test folder.
The images are not corrupted and are valid: I watched them in the Finder and load some in Preview (LiveText to get some text from them).
The trouble is elsewhere. I go to test Julia’s advice.
If Picture.Open fails for any other reason, Nil is returned with no other error information.
so, your problem is that you are getting this ‘any other reason’ and you don’t know why.
That is why I suggested you to try to show/log more information when OffscreenPict is Nil, maybe that will help you find what is this ‘any other reason’. Good luck.
I added .Name to the FolderItem and I get the faultive image who is correct (loads in Previw / QuickView).
Time to eat and then implement Mike suggestions to avoid more troubles (in the Method who will store the file names in an Array to sort them; more easy there).
Operating systems, including macOS and Windows, may sometimes use hidden (invisible) files or folders inside folders.
On macOS in the Finder, you can toggle whether to show or hide these invisible folders with this keystroke: ⌘-Shift-. (hold the Command (⌘) key and Shift key, and press the Period key)
Can a faultive image be loaded in Preview/QuickView but fail in Xojo?
Unless you can open that image in Xojo you will know if the file is at fault or Xojo, for some other reason, can’t load that image at the specific point with your program.
If you move that image out of the folder, does your program fails at the 12th image too (a different one)?
On macOS, invisible files:
.DS_Store is created wen you Open the folder (and move / resize it)
.Icon\r is created when you add a custom Icon
to your folder (item).
Some other exists and there are rules for how they were added.
I was “cautious” about these…
New file sort feature will take care about that. I do not added sooner because of the “Left Key” that do works… sometimes trouble That distract my attention.
macOS user since 1986 (and I am able to forget things )