Unexpected behaviour of display.save function on storyboard

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 :frowning:
 
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

Can anyone help me? It’s really urgent…

Why are you trying this in a media listener? Problem may be that your image hasn’t been added to storyboard view.

You can save you image directly from media.capture if that is what you want: http://docs.coronalabs.com/api/library/media/capturePhoto.html#TOC

Daniel

If I delete the line (line 43) :

  1. display.save( testImage, { filename=“original.png”, baseDir=system.DocumentsDirectory})

from the code , it’ll just show me the Image, as I want it to, so it doesn’t related to capturePhoto… I just want the user to select a photo from the gallery and then the app will save it in the Documents lib so it would be able to use the selected pic in the next scene…

Please refer to documemetation. Use the destination parameter in media.selectPhoto: http://docs.coronalabs.com/api/library/media/selectPhoto.html

media.selectPhoto ({ listener = myListener [, mediaSource] [, destination] [, origin] [, permittedArrowDirections] })

The problem is most likely due to putting the image into a display  group. More info here :

http://forums.coronalabs.com/topic/50194-displaysave-function-cannot-work-with-displaygroup/

Recode this line to :

-- testImage = display.newImage( mainGroup, "bukkit.png") testImage = display.newImage( "bukkit.png")

Can anyone help me? It’s really urgent…

Why are you trying this in a media listener? Problem may be that your image hasn’t been added to storyboard view.

You can save you image directly from media.capture if that is what you want: http://docs.coronalabs.com/api/library/media/capturePhoto.html#TOC

Daniel

If I delete the line (line 43) :

  1. display.save( testImage, { filename=“original.png”, baseDir=system.DocumentsDirectory})

from the code , it’ll just show me the Image, as I want it to, so it doesn’t related to capturePhoto… I just want the user to select a photo from the gallery and then the app will save it in the Documents lib so it would be able to use the selected pic in the next scene…

Please refer to documemetation. Use the destination parameter in media.selectPhoto: http://docs.coronalabs.com/api/library/media/selectPhoto.html

media.selectPhoto ({ listener = myListener [, mediaSource] [, destination] [, origin] [, permittedArrowDirections] })

The problem is most likely due to putting the image into a display  group. More info here :

http://forums.coronalabs.com/topic/50194-displaysave-function-cannot-work-with-displaygroup/

Recode this line to :

-- testImage = display.newImage( mainGroup, "bukkit.png") testImage = display.newImage( "bukkit.png")