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.