We bought the Corona Enterprise in order to implement the function which convert group of display objects into one object.
Existing function [lua]display.capture()[/lua]does not work correctly with group which contains lines and the image; function [lua]display.save()[/lua]work only through file; and use any of these functions leads to loss of quality.
But we don’t have access to a rendered display object and don’t know algorithm of drawing display objects.
So we want to implement our own algorithm of rasterization. [import]uid: 103808 topic_id: 33456 reply_id: 333456[/import]
We actually don’t provide access to our display objects and our rendering system in Enterprise because it is implemented in C++ using the Android NDK.
I’m interested in knowing what exactly is going wrong with our capture APIs. We’re not aware of any issues (other than a stride issue on specific devices which create skewed images), so if you could let us know, then this could benefit all Corona developers. Regarding how captures are achieved, we do a glReadPixels() to capture exactly what you see on the screen. Pretty simple… but note that it won’t be able to capture anything outside of the screen, so if the bounds of your group exceeds the screen bounds, then the capture image will be cropped to fit.
Regarding capture image quality, on Android, we support saving an image to PNG. Just give the [lua]display.save()[/lua] function a file name with a *.png extension and it will save to PNG for you. [import]uid: 32256 topic_id: 33456 reply_id: 132967[/import]
We actually don’t provide access to our display objects and our rendering system in Enterprise because it is implemented in C++ using the Android NDK.
I’m interested in knowing what exactly is going wrong with our capture APIs. We’re not aware of any issues (other than a stride issue on specific devices which create skewed images), so if you could let us know, then this could benefit all Corona developers. Regarding how captures are achieved, we do a glReadPixels() to capture exactly what you see on the screen. Pretty simple… but note that it won’t be able to capture anything outside of the screen, so if the bounds of your group exceeds the screen bounds, then the capture image will be cropped to fit.
Regarding capture image quality, on Android, we support saving an image to PNG. Just give the [lua]display.save()[/lua] function a file name with a *.png extension and it will save to PNG for you. [import]uid: 32256 topic_id: 33456 reply_id: 132967[/import]
Ok, on android problem solved… But on iOS next code work works incorrectly when parameter “antialias” set to true in config.lua:
[lua]local w, h = display.contentWidth, display.contentHeight
math.randomseed(system.getTimer())
– load background image and add it to the group
local group = display.newGroup()
local img = display.newImageRect(group, “orangeBackground.png”, w, h)
img.x, img.y = w/2, h/2
– draw 10 random lines and add them to the same group
for i = 1, 10, 1 do
local x1, x2 = math.random(0, w), math.random(0, w)
local y1, y2 = math.random(0, h), math.random(0, h)
local normalX1, normalY1 = math.min(x1, x2), math.min(y1, y2)
local normalX2, normalY2 = math.max(x1, x2), math.max(y1, y2)
local line = display.newLine(normalX1, normalY1, normalX2, normalY2)
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
line:setColor(r, g, b)
local length = math.random(3, 5)
math.randomseed(system.getTimer() + math.random(500, 5000))
for j = 3, length, 1 do
local x, y = math.random(math.max(0, normalX1-50), math.min(w, normalX2+50)), math.random(math.max(0, normalY1-50), math.min(h, normalY2+50))
line:append(x, y)
end
group:insert(line)
end
– 2 seconds later we get a screenshot of our group
timer.performWithDelay(2000, function()
local screen = display.capture(group)
group:setReferencePoint(display.CenterReferencePoint)
screen:setReferencePoint(display.CenterReferencePoint)
screen.x, screen.y = group.x, group.y
– 5 seconds later we remove our group
timer.performWithDelay(3000, function ()
group:removeSelf()
end)
end)[/lua]
At this link you can see a screenshot of the result of this application on iPad:
https://www.dropbox.com/s/8f9gt9ew1g94gxn/IMG_0008.PNG
And at this link you can see a screenshot of the result of this application without antialias on the same iPad:
https://www.dropbox.com/s/x5rvfvz30ib9b0t/IMG_0009.PNG [import]uid: 103808 topic_id: 33456 reply_id: 133676[/import]
Unfortunately, Corona has known anti-aliasing issues. We recommend that you disable it. Probably not the answer you wanted to hear, but that’s the current state of our rendering system at the moment.
[import]uid: 32256 topic_id: 33456 reply_id: 133723[/import]
I have noticed issues with display capture when the captured image size (width and height) are not multiples of 4. (I have not used lines, so no idea if the anti-aliasing would trigger this issue)…
Since you are using a group, the width and height of the captured area is bounded by the maximum extents of all objects in the group. Once anti-aliasing is applied to the lines, they may grow wider / taller by a pixel or two as the antialias blur is applied to the line. If this is detected in the render/capture, then this could skew the result (the capture area dimensions may not be multiples of 4).
To rule this out, you could limit your line coordinates so they are well within the background image (say 10 pixels in on all sides) and test again. If the image still doesn’t appear right / is not a multiple of 4 for some reason, you could also try using a mask. [import]uid: 79933 topic_id: 33456 reply_id: 133728[/import]
You know what, mpappas is right. This is definitely a stride issue with our image capture. You can tell because the capture image is skewed. Sorry about not paying closer attention. It wasn’t immediately apparent when I looked at your images.
That said, we do have known anti-aliasing issues, but those issues do not appear like this. [import]uid: 32256 topic_id: 33456 reply_id: 133738[/import]
Ok, on android problem solved… But on iOS next code work works incorrectly when parameter “antialias” set to true in config.lua:
[lua]local w, h = display.contentWidth, display.contentHeight
math.randomseed(system.getTimer())
– load background image and add it to the group
local group = display.newGroup()
local img = display.newImageRect(group, “orangeBackground.png”, w, h)
img.x, img.y = w/2, h/2
– draw 10 random lines and add them to the same group
for i = 1, 10, 1 do
local x1, x2 = math.random(0, w), math.random(0, w)
local y1, y2 = math.random(0, h), math.random(0, h)
local normalX1, normalY1 = math.min(x1, x2), math.min(y1, y2)
local normalX2, normalY2 = math.max(x1, x2), math.max(y1, y2)
local line = display.newLine(normalX1, normalY1, normalX2, normalY2)
local r, g, b = math.random(0, 255), math.random(0, 255), math.random(0, 255)
line:setColor(r, g, b)
local length = math.random(3, 5)
math.randomseed(system.getTimer() + math.random(500, 5000))
for j = 3, length, 1 do
local x, y = math.random(math.max(0, normalX1-50), math.min(w, normalX2+50)), math.random(math.max(0, normalY1-50), math.min(h, normalY2+50))
line:append(x, y)
end
group:insert(line)
end
– 2 seconds later we get a screenshot of our group
timer.performWithDelay(2000, function()
local screen = display.capture(group)
group:setReferencePoint(display.CenterReferencePoint)
screen:setReferencePoint(display.CenterReferencePoint)
screen.x, screen.y = group.x, group.y
– 5 seconds later we remove our group
timer.performWithDelay(3000, function ()
group:removeSelf()
end)
end)[/lua]
At this link you can see a screenshot of the result of this application on iPad:
https://www.dropbox.com/s/8f9gt9ew1g94gxn/IMG_0008.PNG
And at this link you can see a screenshot of the result of this application without antialias on the same iPad:
https://www.dropbox.com/s/x5rvfvz30ib9b0t/IMG_0009.PNG [import]uid: 103808 topic_id: 33456 reply_id: 133676[/import]
Unfortunately, Corona has known anti-aliasing issues. We recommend that you disable it. Probably not the answer you wanted to hear, but that’s the current state of our rendering system at the moment.
[import]uid: 32256 topic_id: 33456 reply_id: 133723[/import]
I have noticed issues with display capture when the captured image size (width and height) are not multiples of 4. (I have not used lines, so no idea if the anti-aliasing would trigger this issue)…
Since you are using a group, the width and height of the captured area is bounded by the maximum extents of all objects in the group. Once anti-aliasing is applied to the lines, they may grow wider / taller by a pixel or two as the antialias blur is applied to the line. If this is detected in the render/capture, then this could skew the result (the capture area dimensions may not be multiples of 4).
To rule this out, you could limit your line coordinates so they are well within the background image (say 10 pixels in on all sides) and test again. If the image still doesn’t appear right / is not a multiple of 4 for some reason, you could also try using a mask. [import]uid: 79933 topic_id: 33456 reply_id: 133728[/import]
You know what, mpappas is right. This is definitely a stride issue with our image capture. You can tell because the capture image is skewed. Sorry about not paying closer attention. It wasn’t immediately apparent when I looked at your images.
That said, we do have known anti-aliasing issues, but those issues do not appear like this. [import]uid: 32256 topic_id: 33456 reply_id: 133738[/import]