display.save is running before the image resizes to the display

I am running the code below. It is suppose to save an image to my Documents directory then redirect me to another screen. However, it is saving the image before the image resizes. I tested this part of my app last month when I was working on it, but after finishing up the other sections for some reason it is not working anymore. Here is the code I was working with:

[lua]sessionComplete = function(event)
thePhoto = event.target
thePhoto.x = 0.5 * display.contentWidth
thePhoto.y = 0.5 * display.contentHeight
display.save( thePhoto, “thephoto.jpg”, system.DocumentsDirectory)
if thePhoto then
local w = thePhoto.width
local h = thePhoto.height
print( “w,h = “… w …”,” … h )
end
thePhoto.isVisible = false
director:changeScene(“screen1”,“crossfade”)
end[/lua]

It is suppose to size it to the display, position it, save it, hide it, the redirect the user to another screen. It does everything but resize it.

So I tried this code:

[lua]sessionCompleted = function(event)
if (event.target ~= nil) then
thePhoto = event.target
– Scale and move the image to fit on display completely
thePhoto.w = 384
thePhoto.h = 512
thePhoto.x = 0.5 * display.contentWidth
thePhoto.y = 0.5 * display.contentHeight
thePhoto.isVisible = true
– save it
if (thePhoto.w == 384) then
display.save( thePhoto, “thephoto.jpg”, system.DocumentsDirectory)
director:changeScene(“screen1”,“crossfade”)
thePhoto.isVisible = false
end
if thePhoto then
local w = event.target.width
local h = event.target.height
print( “w,h = “… w …”,” … h )
end

end
end[/lua]
It still doesn’t work. How can I make the app wait for the image to be sized then save it? I thought if I check the width it would work, but I believe it is not really checking the width it is just looking at the value I stated.
Any help or ideas?

Thanks,

Rich [import]uid: 25595 topic_id: 13350 reply_id: 313350[/import]

Hello Rich,

I know that the display.save() function still has bugs capturing the correct portion of the screen on iOS. However, this function should work correctly on Android and the simulator. Can you confirm that your code works correctly on the simulator please?

That said, we do have a fix for the display.save() function on iOS that will be made available in the next daily build. It should fix the issue that you are facing.
[import]uid: 32256 topic_id: 13350 reply_id: 49019[/import]

Hello Joshua,

Thanks for your reply.

I tested on the simulator and it was working. However, while using the simulator one of my images rotates 90 degrees. The other loads fine they have the same dimensions.

I was using the trial version until yesterday when I purchased Corona. So, as far as using the daily builds. Should I use them when I am ready to distribute, or should I use the most current stable release?

Thanks,

Rich [import]uid: 25595 topic_id: 13350 reply_id: 49089[/import]

Hello Rich,

If you need display.save() to work in your app, then I suggest that you try using the first daily build that is made available. It should be relatively stable considering it hasn’t received many changes since our official release. I would say test it out for yourself and if it seems good to you then go ahead and release with it (many of our customers do).

The next daily build will NOT fix the rotated image issue that you see in the simulator. That was written up as a minor bug since it does not happen on Android or iOS devices (ie: simulator only bug).

We are currently making some changes to our daily build system, but hopefully we’ll be able to get it back online soon. [import]uid: 32256 topic_id: 13350 reply_id: 49094[/import]

Thanks for the info. I will wait for the next daily build.

I was able to get the display.save to get better results with this code. However, it seems it still zooms in on the image so it is not quite what I am looking for.

I was using the latest version of Corona Daily Build.

[lua]sessionCompleted = function(event)
if (event.target ~= nil) then
thePhoto = event.target
– Scale the image to fit on display completely
thePhoto.x = 0.5 * display.contentWidth
thePhoto.y = 0.5 * display.contentHeight
thePhoto.isVisible = true
– save it
if thePhoto then
local w = event.target.width
local h = event.target.height
print( “w,h = “… w …”,” … h )
display.save( thePhoto, “thephoto.jpg”, system.DocumentsDirectory)
director:changeScene(“screen1”,“crossfade”)
thePhoto.isVisible = false
end

end
end[/lua] [import]uid: 25595 topic_id: 13350 reply_id: 49697[/import]