Image/Screen Capture Issues

Hello, Ive been trying to select a saved image from the gallery on the android device and have it copy the image and paste it in a folder thats in the applications directory.

I also tried to make it so it opens the image from the gallery and screenshots it and saves it to another folder but I cant get either to work. I fairly new to this and would love any help

Thanks in advance

local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) local capture = display.captureScreen(true) display.save(capture, {filename="Test.png", baseDir="photos", isFullResolution=true, backgroundColor={0,0,0,0} } ) end -- Create the widget local button1 = widget.newButton( { left = 100, top = 200, id = "button1", label = "ScreenShot", onPress = handleButtonEvent } ) local function onComplete( event ) local photo = event.target local s = display.contentHeight / photo.height photo:scale( s,s ) photo.x = centerX photo.y = centerY print( "photo w,h = " .. photo.width .. "," .. photo.height ) end if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource=media.PhotoLibrary, listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end

There  is no baseDir “photos”.

baseDir can be:

system.DocumentsDirectory

system.TemporaryDirectory

, but cannot be:

  • system.ResourceDirectory

If you wanted to save that image to a folder named photos in your app’s ‘documents’ directory do this:

-- You'll need to make the 'photos' folder first: local lfs = require( "lfs" ) local doc\_path = system.pathForFile( "photos", system.DocumentsDirectory ) lfs.mkdir( doc\_path ) -- Now save your image to it display.save(capture, { filename = "photos/Test.png", baseDir = system.DocumentsDirectory, isFullResolution = true, backgroundColor={0,0,0,0} } )

https://docs.coronalabs.com/daily/api/library/display/save.html#basedir-optional

Thank you for the response but how would I work this into the code? 

There  is no baseDir “photos”.

baseDir can be:

system.DocumentsDirectory

system.TemporaryDirectory

, but cannot be:

  • system.ResourceDirectory

If you wanted to save that image to a folder named photos in your app’s ‘documents’ directory do this:

-- You'll need to make the 'photos' folder first: local lfs = require( "lfs" ) local doc\_path = system.pathForFile( "photos", system.DocumentsDirectory ) lfs.mkdir( doc\_path ) -- Now save your image to it display.save(capture, { filename = "photos/Test.png", baseDir = system.DocumentsDirectory, isFullResolution = true, backgroundColor={0,0,0,0} } )

https://docs.coronalabs.com/daily/api/library/display/save.html#basedir-optional

Thank you for the response but how would I work this into the code?