How to display an image downloaded to system.DocumentDirectory?

In my app, I’ve downloaded an image file to the system.DocumentDirectory directory. I’d like to use the image as a button but when I reference it (code below), the app crashes. Am I not referencing the file location correctly?

    logo = widget.newButton({
      defaultFile = 'customlogo.png',
      width = 300, height = 180,
      x = display.contentWidth * 0.5,
      y = display.contentHeight * 0.5 - 250,
      onRelease = function()
        sounds.play('tap')
        display.remove( appSceneGroup)
        appSceneGroup = nil
        composer.gotoScene( "scenes.class", {time=250, effect="crossFade"})
      end

You probably need use baseDir=system.DocumentsDirectory
See Solar2D Documentation — API Reference | Libraries | widget | newButton
Have a nice day:-)

2 Likes

Thank you for your response.

I’m not working with an image sheet, so I’m not clear as to how I would define basedir here.

the baseDir option isn’t just for image sheets. Click on the link that Idurniat provided and read the “2-Image Construction”.

baseDir (optional)
Constant. The base directory where your custom images are located. Default is your project folder (system.ResourceDirectory).

your current code is searching the “customlogo.png” in your project folder.

if you ever want to use an image you downloaded to the system.DocumentsDirectory you always have to include this parameter.

1 Like

Thank you, @proV and @ldurniat . Providing baseDir in the newButton object worked for me.

1 Like

Quite welcome:)