Hello,
this is my first post here, and I have a problem which frustrating me for a while:
In my code I try to save an image to the DocumentsDirectory, but it doesn’t save the full image or it saves black rect… I think it has to do something with the storyboard, but I runned the code and it makes the same errors as well…
Does anyone knows what the problem is? I’m pretty new to Corona and I don’t really know how to fix this one
Here’s the code:
storyboard = require ("storyboard") scene = storyboard.newScene() centerX = display.contentCenterX centerY = display.contentCenterY width = display.contentWidth height = display.contentHeight mainGroup = display.newGroup( ) function scene:createScene(event) end function scene:enterScene(event) selectBtn = display.newText(mainGroup, "TEST", centerX, centerY-100, native.systemFont, 128) takePicButton = display.newText(mainGroup, "Capture Photo", centerX, centerY+200, native.systemFont, 100) function select( event ) if (event.phase == "ended") then if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource = media.PhotoLibrary, listener = savePic } ) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end end end function capture(event) if media.hasSource( media.Camera ) then media.capturePhoto( {listener = savePic } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end end function savePic( event ) testImage = display.newImage( mainGroup, "bukkit.png") testImage.x,testImage.y = centerX, centerY wantedHeight = (width/testImage.width)\*testImage.height -- get height by scaling to the width measurments testImage.height, testImage.width = wantedHeight, width display.save( testImage, { filename="original.png", baseDir=system.DocumentsDirectory}) storyboard.gotoScene( "game" ) end selectBtn:addEventListener("touch", savePic) takePicButton:addEventListener("touch", capture) end function scene:exitScene(event) selectBtn:removeEventListener("touch", savePic) takePicButton:removeEventListener("touch", capture) mainGroup:removeSelf( ) mainGroup = nil end function scene:destroyScene(checkMemory) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene
Thanks again,
Dan