reload new image after saving cropped image

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

Have you considered trying to destroy and re-create the profile picture upon returning from the change photo overlay? That might give you an easier way to solve this.

Thank you Alex. I had to create new image with random name then save in the tmp folder then delete old image from documents dir and then copy the new image. It’s working but I have to keep reference of the new image file. I think corona caches file and u don’t see the changes until you reload the app even you put ur code in will show view method .

Have you considered trying to destroy and re-create the profile picture upon returning from the change photo overlay? That might give you an easier way to solve this.

Thank you Alex. I had to create new image with random name then save in the tmp folder then delete old image from documents dir and then copy the new image. It’s working but I have to keep reference of the new image file. I think corona caches file and u don’t see the changes until you reload the app even you put ur code in will show view method .