Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local M = {}
- function M.save(photo, newFileName, width, height)
- -- End size we want, defaults are profile image size
- local endWidth = 256 * display.contentScaleX
- local endHeight = 256 * display.contentScaleY
- if width then endWidth = width * display.contentScaleX end
- if height then endHeight = height * display.contentScaleY end
- 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, {filename=newFileName, baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0, 0, 0, 0}})
- local syncResults, syncErrStr = native.setSync(newFileName, {iCloudBackup = false}) -- Required or app gets declined for iOS
- myCaptureImage:removeSelf() -- Remove captured image since we have the image from camera already visible
- myCaptureImage = nil
- tempGroup:removeSelf()
- tempGroup = nil
- end
- return M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement