You can try my function.:
[lua]
– @param photo displayObject Such as a captured image from a camera
– @param newFileName String Name of new image file in documents directory. Ending in .png or .jpg
– @param width int The px width of final image in documents directory
– @param height int The px height of final image in documents directory
local function saveImage(photo, newFileName, width, height)
local endWidth = width * display.contentScaleX
local endHeight = height * display.contentScaleY
local tempGroup = display.newGroup()
photo.anchorX = 0.5
photo.anchorY = 0.5
photo.x = display.contentCenterX
photo.y = display.contentCenterY
tempGroup:insert(photo)
– Find the bigger scale out of widht or height so it will fill in the crop
local scale = math.max(endWidth / photo.contentWidth, endHeight / photo.contentHeight)
photo.width = photo.width * scale
photo.height = photo.height * scale
– This object will be used as screen capture boundaries object
local cropArea = display.newRect(display.contentCenterX, display.contentCenterY, endWidth, endHeight)
cropArea.anchorX = 0.5
cropArea.anchorY = 0.5
cropArea.x = display.contentCenterX
cropArea.y = display.contentCenterY
cropArea.alpha = 0
tempGroup:insert(cropArea)
– Now capture the crop area which the user image will be underneith
local myCaptureImage = display.captureBounds(cropArea.contentBounds)
myCaptureImage.anchorX = 0.5
myCaptureImage.anchorY = 0.5
myCaptureImage.x = display.contentCenterX
myCaptureImage.y = display.contentCenterY
display.save(myCaptureImage, newFileName)
myCaptureImage:removeSelf() – Remove captured image since we have the image already visible
myCaptureImage = nil
tempGroup:removeSelf()
tempGroup = nil
end
local someImage = display.newCircle(200, 200, 150)
saveImage(someImage, “test.jpg”, 512, 512)[/lua]