Dynamic image loading

I’m building an app which allows access to a device’s built-in photo library so a user can choose a photo to illustrate a product.

Once the photo is chosen, it’s copied into the apps system.DocumentDirectory folder. There are points in my app where I need to access all of the photos which have been previously chosen by the user so I can display them in a scroll view.

But, I’m having problems referencing the saved images when I create a new display.newImageRect. My current code is below, the loop scans the Documents dir for all *.jpg files and should then create the image rect from the discovered filename, anyone got any idea what I’m doing wrong here? (I’ve removed a load of supporting code that wasn’t necessary)

ta

Chris

 local doc\_path = system.pathForFile( "", system.DocumentsDirectory ) local imgFileCount = 0 for file in lfs.dir( doc\_path ) do if ( string.sub( file, -4, -1 ) ) == ".jpg" then local pathToFile = system.pathForFile( file, system.DocumentsDirectory ) local bg = display.newImageRect( "images/various/photo-film.png", 176, 160 ) local fg = display.newImageRect( pathToFile, 158, 102 ) end end

Lesson learned: Read the API docs properly…

In case anyone needs to know, pass system.DocumentsDirectory as the baseDir parameter ie

local myGfx = display.newImageRect( “imgName”, system.DocumentsDirectory, width, height )

I will now disappear into the corner, shamed by my documentation ignorance… 

Lesson learned: Read the API docs properly…

In case anyone needs to know, pass system.DocumentsDirectory as the baseDir parameter ie

local myGfx = display.newImageRect( “imgName”, system.DocumentsDirectory, width, height )

I will now disappear into the corner, shamed by my documentation ignorance…