Resources not loading in Windows app

I’m new to Xojo and have an issue

I’m writing an app that creates a set of jpg images for users based on input to various fields, I have a choice of background images that I have stored in a resources folder in the app that get placed in the canvas which is the saved as jpeg. This works on MAC creating the jpg files as expected but when run on Windows the background image is not saved but the selected text is. I think that in Windows the backgrounds are not being read from the Resources folder but it is there in the compiled project files.

Think of the canvas as write only and you will be much more successful. Create a picture property in your project and draw to that. Then put draw the picture to the canvas for a preview. When it is time to save the image just use Picture.Save to save it out.

Thanks Bob… I’m using and it works the only thing it does not do on Windows app that it does do on the Mac app is save the canvas backdrop which is taken from a image which is inside the resources folder so think I have missed something that allows the windows app to read image files from resources folder if that makes sense

It would make a little more sense with some punctuation… :slight_smile:

Joking aside, the issue is likely that you are looking for the files by using a folderitem that refers to the resources folder.
And that will have a different path in Windows

But you dont need to do that.

If you drag the images into your project at design time, Xojo will save the images into the resources folder, BUT
you can refer to the images by name in code, as if they were any other variable.

So instead of saying

dim p as picture p =".").child("Resources").child("picture1.jpg") //or whatever thing.backdrop = p

You just refer to picture.jpg as picture1

thing.backdrop = picture1

This is the Canvas.Paint code,

g.ForeColor= &c000000
g.DrawRect 0,0,Me.width,Me.height

Select case selback
case 1
me.Backdrop = image1
case 2
me.Backdrop = image2
case 3
me.Backdrop = image3
case 4
me.Backdrop = image4
case 5
me.Backdrop = image5
case 6
me.Backdrop = image6
case 7
me.Backdrop = image7
end select

g.ForeColor=rgb(230, 230, 230)
g.drawstring (membername,(g.width-g.stringwidth(membername))\2,525)

It creates jpg files perfectly on OSX but Windows it does not have the background image just a plain white background.

image1 - 8 are in a folder called Resources

Also GDI+ is enabled

The more you try to read that the more frustrated you will become. The backdrop is essentially a write only property of the canvas and not everything you put on it is readable no matter what platform. And you have to read it to save it.

Take all your code out of the canvas and put it in a function that returns a picture.

In your canvas paint event you will call the function to draw the picture to a new image and place it in the backdrop.

In your save event you will also call the function to draw the picture to a new image and use Picture.Save to write the file.

Still have same issue after changing code as suggested to draw into picture, the problem is with finding the resource folder under windows as it gets renamed

Resolved using

resfoldername = replace(App.ExecutableFile.Name, “.exe”, “”)+" Resources"
resfolder = app.ExecutableFile.Parent.Child(resfoldername)

Then using GetFolderItem and Picture.Open to draw the background image

The best way to access the Resources folder is with my module TPSF
It makes cross-platform access easy. It uses declares by Sam to access the Mac side properly, and keeps track of the Windows resources folder (has different names from different IDE versions)

Using Jeff’s code example above:

dim p as picture
p ="mypicture.jpg"))
thing.backdrop = p

I would have chimed in earlier, but it seemed like a graphics drawing issue from the thread, not a locations issue :stuck_out_tongue:

What has that resolved?
You dont need to look in the resources folder to get the pictures.

The existing code should have been working:

Select case selback case 1 me.Backdrop = image1

Wasnt the problem that you couldnt save the backdrop as an image?

Bob’s suggestion is the way to go.

Create a picture (TEMPPIC) the same size as the canvas.
Draw your image on TEMPPIC
Draw your text on TEMPPIC

In the canvas’ paint event, draw the TEMPPIC picture, or (if you must), set the backdrop to be TEMPPIC

But when you save, save the TEMPPIC not the .background property