Corrupted image when using display.save()

Hello,
I’m using the display.save() method to save some images within my application but it only seems to work intermittently. I am trying to save an imageRect object, and sometimes it works as expected and other times it creates the image that looks a bit corrupted such as the one attached.

Image being copied:
initial_image

Corrupted Image:
initial_image

My code looks similar to this (although I removed some additional logic to make it simpler to read).

local function saveWithDelay(event)
    display.save(event.source.itemToSave, { baseDir = system.ApplicationSupportDirectory, filename="new_image.png", captureOffscreenArea=true})
end

local imageRect = display.newImageRect( imageFile , baseDir, imageWidth, imageHeight)
local tm = timer.performWithDelay( 100, saveWithDelay )
tm.params.itemToSave = imageRect

Has anyone encountered this problem?

Also, I’m seeing this on the simulator. I have not tested this on another device yet.

Hey, I’ve used display.save() several times and I never got this issue. Why don’t you try to insert that image into a group and save the group instead the display image, this may help you to understand why this is happening if you don’t get the same result.
Have you tried increasing the delay of the timer?

1 Like

I’ve encountered some weirdness with display.save() when working with several custom built shaders applied on standard display objects. That being said, I’ve never had issues when using display.save() under “normal, non-crazy shader circumstances”.

1 Like

Thanks for the replies. I’m not doing anything with shaders. The only thing I do (which I didn’t include in the code above) is move the object to the back of the scene’s view so that the user doesn’t see the object that is being saved.

I’ll try the suggestions of wrapping the object in a group and increasing the timer.

Fortunately I wasn’t seeing the issue when testing this on an iPhone, and I only encountered this on the simulator (on Mac).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.