Display.save goes wild on different devices.

When I use display.save to save parts of my interface (it’s not important which parts and for what reason) to the local device, different devices give out completely different and unexpected results, to test this on your own simply do:

local text1 = display.newText("Test text", 0, 0, your\_choice\_of\_font, 36);   local text2 = display.newText("Test text", 0, 0, your\_choice\_of\_font, 36); --Changing the color of the second text text2:setFillColor(1,0,0);   --Creating and filling a display group, to be saved. local save\_group  = display.newGroup(); save\_group:insert(text2);   --Saving the display group as a png display.save(save\_group,"blabla.png",isFullResolution=true});   --Killing the group, we don't need it any more. save\_group:removeSelf() save\_group = nil;   --Loading the newly created image. local loaded\_image = display.newImage("blabla.png",system.DocumentsDirectory,0,0,false);

Now run this code in your simulator, and you’ll see, on iPhone 5, the original text and the loaded image (you may want to move them around, to align them) are exactly the same, but on GalaxySIII? the image is a little bigger then the text… on iPad, event bigger… on iPad Retina? the image saved is almost 4 times larger then the text it was saved from.

Please, is this a known bug? am I missing something here?

I just came across the same problem.

In my scenario I have two small images with a static width and height.

So what I do after loading the images created with display.save(), is to set their width and the height again:

local snapshot = display.newImage( “snapshot.png”,system.DocumentsDirectory)

snapshot.width = 32

snapshot.height = 32

This seems to work fine on iPhone 5S, Samsung II and on the simulator so far.

I’ll give it a try, although my snapshot is of some text that changes (I snapshot text, then blur it, then save it, then load it, and use it behind the original text to have a glow effect), so sizes are not fixed, but I’ll see if I can’t manage it some how. thanks for the idea, I’ll keep you updated if it worked for me.

Yep, that worked for me, slap me and call me stupid, I don’t know why I didn’t think of this simple solution by myself… I guess I’m too hard set on fixing things that go wrong then to find a workaround them… :slight_smile:

Thanks again!

hey there,

well, I believe setting the width and height like that is not as smooth or recommended like setting it with the scale() method but it works.

In your case I would prefer to not save it at all but to use snapshots and apply filter to it. With that you save a lot of ressources performance-wise.

The problem with using just the snapshot and not saving, is that snapshop is in the openGL, and android, on going to standby mode, cleans the openGL library, so when the device returns from standby, anything you made with snapshot is not there, and this also distorts everything behind where your snapshot was, see:

http://forums.coronalabs.com/topic/46114-snapshot-items-distort-when-device-returns-from-standby/

The size difference in your images across devices is due to display.save capturing in the devices Native Resolution (see display.save docs). Retina devices are of course much higher density in the same square inches of screen space, so they save a lot more pixels.

Your solution works great, but if you would rather save the image at your content scale (so the saved images are smaller for instance, or all saved images across devices are the same pixel dimensions), you can change the scale of what is being captured using display.ScaleX,Y before the save, and restore it afterwards.  This would allow you to make all saved images the same pixel dimensions across devices.

I just came across the same problem.

In my scenario I have two small images with a static width and height.

So what I do after loading the images created with display.save(), is to set their width and the height again:

local snapshot = display.newImage( “snapshot.png”,system.DocumentsDirectory)

snapshot.width = 32

snapshot.height = 32

This seems to work fine on iPhone 5S, Samsung II and on the simulator so far.

I’ll give it a try, although my snapshot is of some text that changes (I snapshot text, then blur it, then save it, then load it, and use it behind the original text to have a glow effect), so sizes are not fixed, but I’ll see if I can’t manage it some how. thanks for the idea, I’ll keep you updated if it worked for me.

Yep, that worked for me, slap me and call me stupid, I don’t know why I didn’t think of this simple solution by myself… I guess I’m too hard set on fixing things that go wrong then to find a workaround them… :slight_smile:

Thanks again!

hey there,

well, I believe setting the width and height like that is not as smooth or recommended like setting it with the scale() method but it works.

In your case I would prefer to not save it at all but to use snapshots and apply filter to it. With that you save a lot of ressources performance-wise.

The problem with using just the snapshot and not saving, is that snapshop is in the openGL, and android, on going to standby mode, cleans the openGL library, so when the device returns from standby, anything you made with snapshot is not there, and this also distorts everything behind where your snapshot was, see:

http://forums.coronalabs.com/topic/46114-snapshot-items-distort-when-device-returns-from-standby/

The size difference in your images across devices is due to display.save capturing in the devices Native Resolution (see display.save docs). Retina devices are of course much higher density in the same square inches of screen space, so they save a lot more pixels.

Your solution works great, but if you would rather save the image at your content scale (so the saved images are smaller for instance, or all saved images across devices are the same pixel dimensions), you can change the scale of what is being captured using display.ScaleX,Y before the save, and restore it afterwards.  This would allow you to make all saved images the same pixel dimensions across devices.