Load album images into app

Hi,

I’m creating an app, that displays some images on screen1. screen2 is exactly the same except that the user should click an image, choose one of his/her images from the photo-album and have it in place of the clicked image.

I copied the images to the documents directory naming them image_a, image_b… But how do I handle it when the user has chosen his own image from the album? Just saving as image_a… again does not work.
Incrementing it every time seems to get a little bit out of control with 100+ images. [import]uid: 103773 topic_id: 22268 reply_id: 322268[/import]

???

cant figure out what you are doing… can you post some code, more details?

C. [import]uid: 24 topic_id: 22268 reply_id: 88738[/import]

Hi,

basicly, I have layouted in gumbo two scenes managed by storyboard which look the same.

in main.lua the image files are copied to the system documents.

scene1.lua and scene2.lua are like:

local dispObj\_1 = display.newImageRect( "image\_a.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_1.x = 180  
 dispObj\_1.y = 180  
  
local dispObj\_2 = display.newImageRect( "image\_b.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_2.x = 510  
 dispObj\_2.y = 180  
  
local dispObj\_3 = display.newImageRect( "image\_c.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_3.x = 840  
 dispObj\_3.y = 180  
  
local dispObj\_4 = display.newImageRect( "image\_d.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_4.x = 180  
 dispObj\_4.y = 520  
  
local dispObj\_5 = display.newImageRect( "image\_e.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_5.x = 510  
 dispObj\_5.y = 520  
  
local dispObj\_6 = display.newImageRect( "image\_f.png", system.DocumentsDirectory, 300, 300 )  
 dispObj\_6.x = 840  
 dispObj\_6.y = 520  
  
local button = display.newImageRect( "button.png", 20, 20)  
 button.x = 1010  
 button.y = 384  

Now when the user touches one image on scene2.lua (lets say image_a), he should be taken to his photo-album, choose another image and image_a should be replaced by that new image like so:

local filePath = {baseDir = system.DocumentsDirectory, filename = "image\_a.png"}  
local function touchDispObj\_1(event)  
 if event.phase == "began" and dispObj\_1Touch == true then  
 media.show(media.Camera, touchDispObj\_1, filePath)  
 end  
end  
  

In the api docs I read that this won’t work, because corona still reads “old” image_a from some cache. So how can I handle the new user chosen images? Save it as image_a1++? [import]uid: 103773 topic_id: 22268 reply_id: 88818[/import]

@hebbes,
there is no replace mechanism in CoronaSDK, from what I understand you are trying to replace the images on screen with the chosen one by the user from their Photo Album.

The only way to do so is to remove the image and place the new image in it’s place in the same location.
[import]uid: 3826 topic_id: 22268 reply_id: 88820[/import]

Hi,

JayantV, yes I’m trying to replace the images with the one the user choses.

What I understand from the api docs, corona caches the images, so when I delete the old image_a.png and replace it with a new image called image_a.png also, the old is still displayed in place.

So I have to rename the images, the user chooses.

But what do you think is the best way for this? Call it image_a1 and increment it every time when the user chooses another one again? [import]uid: 103773 topic_id: 22268 reply_id: 88912[/import]