the copy files step is pretty easy
create one and make sure the destination is set to resources (and maybe a subdir as well which I will use for this example)
so now when we run of build the images will be in Resources > images
on to the code
Add a method to the ResourceImageAccess module
Private Function findImagesDir() As folderitem
Dim f As folderitem = SpecialFolder.Resources
If f Is Nil Or f.exists = False Then
Return Nil
End If
// note this should match the SUBDIR name from the copy file step !!!!!!
If f.Child("Images") Is Nil Or f.Child("Images").Exists = False Then
Return Nil
End If
Return f.Child("Images")
End Function
This will locate the dir where the copy file step put all the images
Now we need to create a “multiimage”
Add the following method to the module
This method will look for png & jpg images
It also defaults to looking for the 1x WITHOUT any @1x , and the 2x and 3x with @2x and @3x suffixes to the base name( normal macOS naming for image sets)
Private Function multiimage(baseName as string) As picture
Dim imageRoot As folderitem = findImagesDir
If imageRoot Is Nil Then
Return Nil
End If
Dim imageFolderitem As folderitem
Dim images() As picture
// lets see what we can find - we can / could use png, jpg - we'll prefer pngs
// 1x image
imageFolderitem = imageRoot.Child(basename+".png")
If imageFolderitem Is Nil Or imageFolderitem.exists = False Then
imageFolderitem = imageRoot.Child(basename+".jpg")
End If
If ((imageFolderitem Is Nil) = False) And (imageFolderitem.exists = True) Then
images.append Picture.Open(imageFolderitem)
End If
// 2x image
imageFolderitem = imageRoot.Child(basename+"@2x.png")
If imageFolderitem Is Nil Or imageFolderitem.exists = False Then
imageFolderitem = imageRoot.Child(basename+"@2x.jpg")
End If
If ((imageFolderitem Is Nil) = False) And (imageFolderitem.exists = True) Then
images.append Picture.Open(imageFolderitem)
End If
// 3x image
imageFolderitem = imageRoot.Child(basename+"@3x.png")
If imageFolderitem Is Nil Or imageFolderitem.exists = False Then
imageFolderitem = imageRoot.Child(basename+"@3x.jpg")
End If
If ((imageFolderitem Is Nil) = False) And (imageFolderitem.exists = True) Then
images.append Picture.Open(imageFolderitem)
End If
Try
Dim multiPicture As New Picture(images(0).width,images(0).height, images )
Return multiPicture
Catch iax As InvalidArgumentException
Catch noe As NilObjectException
Catch oom As OutOfMemoryException
End Try
Return Nil
End Function
And now Beeker_msn, in my case, is
Public Function Beeker_msn() As picture
Return multiImage( "Beeker_msn" )
End Function
Now for the glitches
With images dragged into the IDE you can set backdrops etc in the IDE by selecting an image
That will not work with this mechanism. It cant. The IDE has no idea about our custom mechanism
So anywhere we had set a property we will need a couple lines of code to set the property
In this screen shot I’ve cloned the canvas so the one on the left uses an image dragged into the project and the one on the right will set the backdrop property
And so the open event of the right hand canvas reads
Me.Backdrop = Beeker_msn
me.invalidate
- now you may notice that the image I have is named Beeker_msn1 and my method Beeker_msn.
In order to do this demo I cant name them EXACTLY the same as things wont work
And now I cant simply add whatever methods I need to the module and remove the images dropped into my project and get rid of the giant resources file.