I’m trying to make an application to view some pictures taken from my webiste (“http//toytoy365.com”).
I saved the pictures to the system.DocumentsDirectory, and can browse them with display.newImage() method.
I would allow the user to save them to the device album.
Is there any way/method to move files from system.DocumentsDirectory to the album ?
You can save photos to the device’s album in an indirect way. If you display the photo on the screen, you can use display.captureScreen( true ), and it will save the photo.
I tried with the function “display.captureScreen(true)”.
But to make some kind of animation, I created an image with display.newImage() wich appear and fade away.
function beforeSave()
image\_temp = display.newImage(images\_name[imgNum], system.DocumentsDirectory)
image\_temp.alpha = 0
local scaleImage = 1
if image\_temp.width \> image\_temp.height then
scaleImage = screenW/image\_temp.width
image\_temp.xScale = scaleImage
image\_temp.yScale = scaleImage
image\_width = math.ceil(image\_temp.width\*scaleImage)
image\_height = math.ceil(image\_temp.height\*scaleImage)
else
scaleImage = screenH/image\_temp.height
image\_temp.xScale = scaleImage
image\_temp.yScale = scaleImage
image\_width = math.ceil(image\_temp.width\*scaleImage)
image\_height = math.ceil(image\_temp.height\*scaleImage)
end
image\_temp.x = images[imgNum].x -- position x of the original image
image\_temp.y = images[imgNum].y -- position y of the original image
transition.to(image\_temp, { time=1000, alpha=1, transition=easing.outExpo, onComplete=saveIt } )
end
function saveIt()
display.captureScreen(true)
afterSave()
end
function afterSave()
transition.to(image\_temp, { time=1000, x=0, transition=easing.outExpo } )
transition.to(image\_temp, { time=1000, y=0, transition=easing.outExpo } )
transition.to(image\_temp, { time=1000, alpha=0, transition=easing.outExpo } )
transition.to(image\_temp, { time=1000, xScale=0, transition=easing.outExpo } )
transition.to(image\_temp, { time=1000, yScale=0, transition=easing.outExpo } )
timer.performWithDelay(400, afterSaveEnd)
end
function afterSaveEnd()
image\_temp:removeSelf()
transition.to(mainGroup, { time=500, alpha=1, transition=easing.outExpo } )
transition.to(infosGroup, { time=500, alpha=1, transition=easing.outExpo } )
transition.to(btnLess, { time=500, alpha=1, transition=easing.outExpo } )
end
In the function afterSaveEnd(), the image doesn’t remove because of display.captureScreen(true). Did I make some mistake ?
Your afterSave function is doing five transitions on the same image. All five will run in parallel, which I’m not sure is what you intended. You could create one transition that does all the object transitions.
The other problem is your transitions run for 1000 msec (1 second) but you also start a 400 msec timer which will end first and call afterSaveEnd and delete image_temp before the transition timers have finished.
Just in case you are not aware of it, the timer function and transitions happen at the end of the function and do not happen in sequence. All your timers will fire and execute at the same time.
Thank you for the answer.
But it doesn’t work either.
I tried something else.
Move the buttons “save the picture” and the text (created with display.newText) “out of the screen” by setting “.x = .x + some_big_value” so as to I can see only the picture to make the “display.captureScreen(true)”.
But there is some kind of bug. To see it, I set “some_big_value” to 100.
Then here’s a screen shot with the bug.
It seems that the function “display.captureScreen(true)” duplicate what there is on the screen ?
The purpose of display.captureScreen(true) is to capture what is currently displayed on the screen. It returns the image as an object. By setting the parameter to “true”, it also saves the image in the device’s Album.
I didn’t know that this method return an image as an object. But I have to remove it after using this method.
And I didn’t know if it’s normal. [import]uid: 7826 topic_id: 1659 reply_id: 4873[/import]
But as they no way to move pictures from /Documents directory to the album’s device, I will choose the choose display.captureScreen(true) method to do that.