I have an app which allows the user to take a picture from either the camera or gallery.
The app then saves this image to the TemporaryDirectory, rescales it to 0.25, saves a thumbnail, and then rescales back to 1.
It worked fine before, but recently we have noticed that the images kept being displayed as black squares, sometimes with text in them. If I look in the sandbox then the images in the temp directory appear to be fine though.
I’ve made a quick sample, and I’ve found that when display.save is called, the image disappears entirely:
local \_W, \_H = display.contentWidth, display.contentHeight local isSimulator = "simulator" == system.getInfo("environment") local photo local function onCamera(e) local onComplete = function(event) if event.target then --remove photo if it already exists if photo then photo:removeSelf() photo = nil end local photogroup = display.newGroup() photo = event.target photo.x, photo.y = \_W \* 0.5, \_W \* 0.5 photogroup:insert(photo) --save image --THIS CAUSES IMAGE TO DISAPPEAR local baseDir = system.TemporaryDirectory display.save(photogroup, "myPhoto.jpg", baseDir) end end local function onChoiceComplete(event) if event.index == 1 then if not isSimulator then local filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" } media.show( media.Camera, onComplete ) else media.show( media.Camera, onComplete) end elseif event.index == 2 then if media.hasSource( media.PhotoLibrary ) then if not isSimulator then local filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" } media.show( media.PhotoLibrary, onComplete ) else media.show( media.PhotoLibrary, onComplete) end end end end if e.phase == "ended" then local alert = native.showAlert( "Photo", "Choose photo from:", { "Camera","Gallery"},onChoiceComplete ) end end local background = display.newRect(\_W \* 0.5, \_H \* 0.5, \_W, \_H) background:setFillColor( 1, 0, 0 ) local cameraButton = display.newRoundedRect(\_W \* 0.5, 50, 50, 50, 10) cameraButton:addEventListener( "touch", onCamera ) cameraButton.strokeWidth = 2 cameraButton:setStrokeColor( 0 ) local cameraText = display.newText( "Camera", cameraButton.x, cameraButton.y, native.systemFont, 12 ) cameraText:setFillColor( 0 )
Has anyone noticed the same thing happening to them?
I’ve thinned out my sample to remove the scaling beforehand, but the problem still persists. I’ve also tried using:
display.save( photogroup, { filename="myPhoto.jpg", baseDir=system.TemporaryDirectory, isFullResolution=true } )
which did exactly the same thing.