Picture darkens when using “display.save” several times

Greetings.

 

I’m new here, and usually don’t like to use forums because I have the feeling that I’m asking for a nonsense, but here I go.

 

I have been looking for a post that could help me but haven’t found anything.

 

I’m trying to modify a picture (png). As long as we don’t have libraries for that (by now, I hope), I load the picture as a texture for a display.newRect. The newRect size is the same as the picture size (no scale).

 

I create another newRect with 1x1px size, I put it wherever I want (over the picture), then insert both objects inside a group, and finally save the results.

 

The issue is that when I repeat this process with the same picture, the older pixels go to black.

 

If you run the code inside Corona simulator, it works perfectly, but have tested it in real devices (a HTC One M7 and a Samsung Galaxy S3), and if I repeat the process 256 times, the older pixels go to black.

 

Corona simulator:

[sharedmedia=core:attachments:5182]

 

Galaxy S3:

[sharedmedia=core:attachments:5183]

 

HTC one M7:

[sharedmedia=core:attachments:5184]

 

Here is a demo code:

 

[lua]

display.setDefault(“background”, .8)

 

local ccx, ccy = display.contentCenterX, display.contentCenterY

local dcw, dch = display.contentWidth, display.contentHeight

 

local c = 0

local txt1 = display.newText("", ccx, 30, native.systemFont, 30)

    txt1:setFillColor(0)

local txt2 = display.newText("", ccx, 75, native.systemFont, 30)

    txt2:setFillColor(0)

local function refreshTxt(event)

    txt1.text = string.format("(r, g, b, a) = (%5.3f, %5.3f, %5.3f, %5.3f)", event.r, event.g, event.b, event.a)

    txt2.text = "Setting pixel: " … c

end

 

hidegrp = display.newGroup()

hidegrp.isVisible = false

 

local grp = display.newGroup()

    grp.x, grp.y = ccx - 350, ccy - 450

local box = display.newRect(350, 500, 700, 1000)

    box:setFillColor(1)

    grp:insert(box)

 

display.save(grp, {

    filename = “box_0.png”,

    baseDir = system.DocumentsDirectory,

    isFullResolution = true,

    backgroundColor = {0, 0, 0, 0}

})

 

local pix = display.newRect(0, 0, 50, 50)

    pix.anchorX, pix.anchorY = 1, 1

    pix:setFillColor(1, 0, 0, 1)

    hidegrp:insert(pix)

local x, y = 1, 1

local function listener()

    display.setDefault(“magTextureFilter”, “nearest”)

    box.fill = {

        type = “image”,

        filename = “box_” … c … “.png”,

        baseDir = system.DocumentsDirectory

    }

    display.setDefault(“magTextureFilter”, “linear”)

    pix.x, pix.y = 50 * x, 50 * y

    grp:insert(pix)

    c = c + 1

    display.save(grp, {

        filename = “box_” … c … “.png”,

        baseDir = system.DocumentsDirectory,

        isFullResolution = true,

    })

    hidegrp:insert(pix)

    display.colorSample(ccx - 350 + 5, ccy - 450 + 5, refreshTxt)

    x = x + 1

    if x > 14 then

        x = 1

        y = y == 20 and 1 or y + 1

    end

end

timer.performWithDelay(500, listener, 256)

[/lua]

 

What’s happening?

 

Thanks in advance.

 

 

:frowning:

Could anybody help me with this?

Thanks again.

Hi @mjram,

There’s nothing wrong with asking specific questions in the forums, that’s why we have them! :slight_smile:

Considering that this doesn’t happen in the Simulator, my best guess is that it’s something hardware-related to the device(s) and how, when you save the image to file back and forth, the OS is doing some kind of “conversion” or down-sampling of the file, and that’s basically not in your control (or Corona’s).

Can you explain your “real world” intention with this process? What is your goal with saving files back and forth so many consecutive times? What is your app intending to do?

Best regards,

Brent

Thanks for the reply, Brent.

I was trying to save a picture modified by the user: load a picture, do some changes and then, when he/she finishes, save back again with the changes included, but as long as I was saving I realized that something was going wrong.

Now I’m using a snapshot over the original picture, and saving all the changes to a table sequentially.

What is strange for me is that I’m using two different devices with different versions of Android. I’m going to look for more devices and will check to see if the problem is still there.

It could be usefull if somebody that read this can check it inside their own devices (can use the code above).

Regards.

:frowning:

Could anybody help me with this?

Thanks again.

Hi @mjram,

There’s nothing wrong with asking specific questions in the forums, that’s why we have them! :slight_smile:

Considering that this doesn’t happen in the Simulator, my best guess is that it’s something hardware-related to the device(s) and how, when you save the image to file back and forth, the OS is doing some kind of “conversion” or down-sampling of the file, and that’s basically not in your control (or Corona’s).

Can you explain your “real world” intention with this process? What is your goal with saving files back and forth so many consecutive times? What is your app intending to do?

Best regards,

Brent

Thanks for the reply, Brent.

I was trying to save a picture modified by the user: load a picture, do some changes and then, when he/she finishes, save back again with the changes included, but as long as I was saving I realized that something was going wrong.

Now I’m using a snapshot over the original picture, and saving all the changes to a table sequentially.

What is strange for me is that I’m using two different devices with different versions of Android. I’m going to look for more devices and will check to see if the problem is still there.

It could be usefull if somebody that read this can check it inside their own devices (can use the code above).

Regards.