Has anyone figured out how to save an image with exact dimensions when using display.save?

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?

It is possible, within certain limits.  While I’d love to just drop the solution here I cannot as it is part of some paid work.  However, I can say that you need to be careful about the resolution and scaling type you choose in config.lua as that will affect your ability to do this.

So when using a config.lua with dynamic screen fit the display.save can get messed up? That’s bad news!

I wanted to create a tutorial by using a “flashlight” mask on a display captured screen image. Everything works fine, but it only works on the “normal” screen sizes and oversized areas like on the iPhone6 are not shown.

Are you using a big enough mask?

Yes this is possible with corona.

It is possible, within certain limits.  While I’d love to just drop the solution here I cannot as it is part of some paid work.  However, I can say that you need to be careful about the resolution and scaling type you choose in config.lua as that will affect your ability to do this.

So when using a config.lua with dynamic screen fit the display.save can get messed up? That’s bad news!

I wanted to create a tutorial by using a “flashlight” mask on a display captured screen image. Everything works fine, but it only works on the “normal” screen sizes and oversized areas like on the iPhone6 are not shown.

Are you using a big enough mask?

Yes this is possible with corona.