display.save still not working correctly?

Hey there,

I’m using display.save to save down a simple screenshot of a display object or the stage.currentDisplay.

The Win-Simulator seems to save down the image incorrectly - the resulting image is always 0.5x the size of its natural size.

As shown in the lua-example below, I’m simply creating a red rectangle over the whole screen, saving the stage.currentDisplay down, removing the original rectangle and then loading the saved image.

I would expect the image to be the same size as it was pre-saving…
Does this happen on the mac version as well? Can anyone confirm?

See link for screenshot:
http://imageshack.us/photo/my-images/839/errorimage.jpg/

Notice:
-Using Daily Build 649, Win/Android version

  • Using large screen (resolution is high: 1920x1080)
  • This errors happens both when zoomed in or zoomed out in the simulator
  • I do not have any special configuration settings for dynamic scaling

[lua]–create rect
local rect = display.newRect(0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor(255, 1, 1, 255);

local baseDir = system.DocumentsDirectory
local fileName = “entireScreen.jpg”;

–save
display.save( display.currentStage, fileName, baseDir )

–remove rect
rect:removeSelf()

– load saved image
local image = display.newImage(fileName, baseDir)[/lua] [import]uid: 90232 topic_id: 18382 reply_id: 318382[/import]

Do you get the desired results by using display.newImageRect()? (where you specify widht/height).

e.g.
local image = display.newImageRect( fileName, baseDir, 1920, 1080 )

Also, a way to verify this is to go to File > Show Project Sandbox and look in the Documents Directory to see if the saved image is the correct resolution. [import]uid: 52430 topic_id: 18382 reply_id: 70502[/import]

Thanks… but the problem persists even if I do so.

So if I specify the rectangle to be 100x100 and use display.save on it instead of the stage, the resulting image is 50x50. [import]uid: 90232 topic_id: 18382 reply_id: 70568[/import]

i had read it some time ago if image in android is larger than 1024x1024 corona will re size that automatically and this issue has been fixed in new build can u try it with last build.

i think it is a your problem due to very high width and height
:slight_smile:

be my friend ?

http://www.facebook.com/hgvyas123 [import]uid: 12482 topic_id: 18382 reply_id: 70569[/import]

Thanks friend :wink: but since this happens with small rectangles as well it can’t just be a matter of size of a image.

Tried this with build 696 as well, same issue… [import]uid: 90232 topic_id: 18382 reply_id: 70600[/import]

Hello Crowye,

I have confirmed that display.save() is working correctly. If you go to your project’s sandbox by clicking “File\Show Project Sandbox” in the menu and then go to the Documents directory, notice that the image that is saved exactly matches what was captured in pixels. Also notice that if you zoom in or out in the simulator and then restart your app, the saved image file will increase or decrease in size in pixels since it is an exact screen capture of what you see onscreen.

The problem is how you are loading the image. You need to specify what the size of the loaded image needs to be in “content coordinates”. You need to replace your display.newImage() function call with the following…

[lua]local image = display.newImageRect(fileName, baseDir, display.currentStage.contentWidth,

display.currentStage.contentHeight)
image.x = display.contentWidth / 2
image.y = display.contentHeight / 2[/lua]

This will size the image to exactly match what was captured. Notice that I’m also centering the image onscreen. If you comment out the image.x/y part, then what happens is that the loaded image will be centered at the top left corner of the screen, making 3/4 of your image positioned off screen.

I highly recommend that you use display.newImageRect() over display.newImage() because it makes it easy to display images consistantly on screens of various resolutions, which is particularly important on mobile devices.

Anyways, I hope this helps! [import]uid: 32256 topic_id: 18382 reply_id: 71109[/import]

Thanks for taking your time!

After your post I tried doing more tests myself and realised that you are right.

I guess wasn’t testing it thoroughly enough on the new build (it was still some weird behaviour on the old).

Anyway, sorry for any extra time it took for you to investigate!

I’m still not 100% sure its always working 100%… but when I’m 100% that I’m actually right about something being amiss, I will definitely post again :slight_smile:

Since my game is using a lot of images with arbitrary dimensions I have a hard time using display.newImageRect, but thanks for the tip!..

Very helpful, overall! [import]uid: 90232 topic_id: 18382 reply_id: 71743[/import]

I’m glad I could help. :slight_smile:

What’s nice about display.newImageRect() is that you can specify the width and height of the image in “content coordinates”. That is, the coordinate system that you set within your config.lua file. This is especially useful if the image that you are loading in pixels does not fit within your content bounds and needs to be rescaled. This function will do the scaling for you.
[import]uid: 32256 topic_id: 18382 reply_id: 71759[/import]