Bulk import images


I wanted to know if there is a way to import large amounts of images into Xojo as ImageSet with different resolution (1x, 2x)

I retrieved country flags from this repo (https://github.com/stefangabos/world_countries) in 16x16 and 32x32 and set name of each file, filenames look like this::


I can drag each image and place the 2x in the ImageSet but it will take a long time to do it.

Is there a way to do this?

Thank you

Create a bas or xml file with the information you need and import the file in your project. But you have to:

a. Learn the bas or xml file format to generate a correct file,
b. have a license to be able to deal with these file formats.

Did you checked IDE Scripting if it helps for that ?

I am not using ImageSet nor IDE Scripting, but this is the direction I would follow if I need to do what you asked, so…

Thank you for the answer,

I never did any IDE scripting, I will look into this.

I have a Xojo Pro license, it should be good I hope.

Tried a bit of xojo_script but I encountered some issues with 2018r4 and 2019r1.1 on Mac

I can not select a folder with SelectProjectItem but it’s working with Location

'Returns false
dim selected as boolean = SelectProjectItem("Resources.Countries")

'Selecting in the IDE the folder and executing
'Returns Resources.Countries

'Select the correct folder
Location = "Resources.Countries"

Next if I want to create a new imageSet using DoCommand

'Creating the new ImageSet 
'Even if I select the folder before executing DoCommand, the imageset will be created in the root folder of the app

'Changing the name of the newly created imageSet
Property("Image1.Name").Value = "ad"

And after that, I do not know how to set the 1x and 2x image of the ImageSet. I looked in the xojo_image file created after the command but could not find any hint on how to set it.

I made a simple test (that always works with the A^pleScript Editor): Record a brand new IDE Script… and get:

DoCommand "NewProject" SelectWindow "Untitled - [IDE Script]" DoCommand "Inspector" PropertyValue("Window1.Name") = "wMain" DoCommand "NewFolder" PropertyValue("Folder1.Name") = "Images" DoCommand "NewImageAsset" PropertyValue("Image1.Name") = "Image1" PropertyValue("Image1.Name") = "Image1" PropertyValue("Image1.Name") = "The_Phantom_1943_01_01"

What I’ve done above:
I created a set of images @1x and @2x,
I launched Xojo 2019r1.1,
I asked for a brand new project and give it a name,
I changed Window1 to wMain,
I asked to create a brand new IDE Script,
I moved the Project window to the right,
With a drag and drop, I imported both images to their respective area,
I noticed that the file name was not used in the PictureSet, so I change it from Image1 to something else (what the image is).
Note: the ‘-’ character (date field separator) is not allowed !

A click in the Stop button leads me the above useless code.

Now, maybe in some hours when the US will Power ON their computer you will get a better answer.

Thank you for your time.

I think I will drag and drop images one by one if I do not find something with the IDE Script. It’s just that it’s take time as my IDE is quite slow and loading after each drag and drop of images.

If you can, wait until the end of the afternoon in case someone who knows send an answer.


Finally, letting a possible solution for others. Maybe not the most optimized but it works

I created a copy files step and dragged all images (normal and @2x) into a subdirectory called “flags” and I used Xojo.IO.SpecialFolder to retrieve the normal and @2x item (with SpecialFolder.GetResource) and used the Constructor of Picture that take an array of picture (normal and 2x) to create the Picture of the flag of a country

'alpha2 contains the 2 characters identifier of a country, e.g.: France -> fr
'Images are fr.png and fr@2x.png
Dim fi1 As Xojo.IO.Folderitem = Xojo.IO.SpecialFolder.GetResource("flags").Child(me.alpha2.ToText+".png")
Dim fi2 As Xojo.IO.Folderitem = Xojo.IO.SpecialFolder.GetResource("flags").Child(me.alpha2.ToText+"@2x.png")
Dim classicFile1 As New FolderItem(fi1.Path, FolderItem.PathTypeNative)
Dim classicFile2 As New FolderItem(fi2.Path, FolderItem.PathTypeNative)
dim p1 as picture = Picture.open(classicFile1)
dim p2 as picture = Picture.open(classicFile2)
dim ps() as Picture
dim p as picture = new picture(p1.Width,p1.Width,ps)
return p