Sure.
I’m cropping an image. I make a newSnapshot that is smaller than the image, add the image to it, use display.save to write snapshot contents to file.
The output file looks correct in terms of what has been cropped.
However by looking in the sandbox, I can see the dimensions of the output file vary depending on the device.
I attach a main.lua and an image a.jpg - when you run the code it makes b.jpg - the cropped output file.
a.jpg is 2448x2448, I am cropping 2048x2048 out of it.
I would expect the output file to be 2048x2048 but it is not.
On smaller devices the output file is smaller. For example on a Nexus One it is 1228x1228
I can live with that.
On larger devices, the output file is very large, on an iPad Air it is 3495x3495
That’s no good…
I suspect that display.save is autoscaling the output file.
I wish it didn’t.
Code attached - and also below;
local function cropImageOnDevice(filename, newFileName, cropX, cropY, cropW, cropH) local photo=display.newImage( filename, system.TemporaryDirectory ) -- set the masking container local tempGroup = display.newSnapshot(cropW, cropH ) tempGroup.x = 0 tempGroup.y = 0 tempGroup.anchorX = 0 tempGroup.anchorY = 0 tempGroup.group:insert(photo) local x0 = cropW \* -0.5 local y0 = cropH \* -0.5 local x = x0 + ( cropX \* -1 ) local y = y0 + ( cropY \* -1 ) photo.x = x photo.y = y photo.anchorX = 0 photo.anchorY = 0 -- save the cropped image display.save( tempGroup, { filename = newFileName, baseDir = system.TemporaryDirectory, isFullResolution = true } ) tempGroup:removeSelf() tempGroup = nil end -- crop image 2448x2448 to 2048x2048 cropImageOnDevice("a.jpg", "b.jpg", 200, 200, 2048, 2048) -- on a Nexus One image is 1228x1228 -- on an iPad Air image is 3495x3495