I had an idea to develop an app where the user creates their own art and one of the main features will be saving the image so they can share it or use it in their own projects.
I’ve been doing research to see if Corona can actually handle this and it looks like the basic functionality is there but people haven’t been able to save an image with precise dimensions. I tried my own experiment and I am running into the same issue. This is the function I’m using to resize, which is based off of code that I found around the forums:
local function save() local capture = display.capture( squareGroup, { saveToPhotoLibrary=false, captureOffscreenArea=true } ) --move the image on screen because captureOffscreenArea doesn't actually work capture.anchorX, capture.anchorY = 0,0 capture.x, capture.y = 0,0 local endWidth = 256 \* display.contentScaleX local endHeight = 256 \* display.contentScaleY print("endWidth and Height", endWidth, endHeight) print("contentWidth and Height", capture.contentWidth, capture.contentHeight) local scale = math.max(endWidth / capture.contentWidth, endHeight / capture.contentHeight) capture.width = capture.width \* scale capture.height = capture.height \* scale print("scale", scale) print("new capture dimensions", capture.width, capture.height) filename = "test"..os.time()..".png" display.save(capture, { filename = filename }) media.save(filename, system.DocumentsDirectory) capture:removeSelf() capture = nil end
In the simulator I get varying dimensions from 254 all the way up to 257. On my Galaxy S6 the resulting image is 255x255. I’m sure that rounding errors with the scale play a part, but even when I set
capture.width = 256 --capture.width \* scale capture.height = 256 --capture.height \* scale
I still get varying sizes. In fact, it seems the rounding error with the scale actual helps get a more accurate number.
I tried using adaptive content scaling and letterbox, neither seems to make a difference.
So is this possible with Corona or not?