hi,
I’ve a dashboard where I show user photo. When you click on the photo it takes you to another scene (change photo)where you can access your device photo , select it then crop it then save it. After saving it takes you back to dashboard and you see the newly saved image. I see images are saving correctly in the folder but it doesn’t show the updated image in the dashboard until I close the app and reopen. I’m using global variable and also composer params to tell whether I need to display new image.
Here are are my codes
dashboard
========
unction scene:show( event ) local sceneGroup = self.view local phase = event.phase local params =event.params or {} local paint={} if fileExists('images/1.jpg', system.DocumentsDirectory) then paint = { type = "image", baseDir= system.DocumentsDirectory, filename = "images/1.jpg" } else paint = { type = "image", filename = "images/placeholder.jpg" } end if phase == "will" then elseif phase == "did" then print(myApp.newphoto) print(params.newphoto) if myApp.newphoto==true then local newImage = display.newCircle(display.contentCenterX, display.contentHeight\*0.20, 60) newImage.x = rect.x newImage.y = rect.y newImage.fill = paint rect:removeSelf() rect= nil sceneGroup:insert(newImage) newImage:addEventListener("touch", pix) print('Reloaded new image') else rect = display.newCircle(display.contentCenterX, display.contentHeight\*0.20, 60) --rect.strokeWidth = 2 rect.fill = paint rect:addEventListener("touch", pix) sceneGroup:insert(rect) end end end
And here is my change photo code
local function savepix(event) if event.phase == "ended" then local capture = display.captureBounds(circle.contentBounds,false) capture.x=circle.x capture.y=circle.y os.remove( system.pathForFile( "images/1.jpg",system.DocumentsDirectory ) ) display.save( capture, { filename="images/1.jpg", baseDir=system.DocumentsDirectory, isFullResolution=false } ) capture:removeSelf(); capture = nil; local options = { newphoto = true, } myApp.newphoto=true composer.gotoScene('view1',{ effect="slideRight",params=options}) end end