Cannot Save Camera Images?

Hi guys,

I’m try to save the images that my camera app is taking but it seems as if it is only activating the camera and displaying the image. When I search my device there is no image found. Also is there a way to make it save into a folder which doesn’t currently exist and therefore creates one. This is the code i’m using with my not saving issue…

[lua]

– 

– Abstract: Camera sample app

– 

– Version: 1.2

– 

– Updated: September 21, 2011

– Update History:

– v1.1 Fixed logic problem where it said “session was cancelled”.

– v1.2 Added Android support.

– Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license

– Copyright © 2011 Corona Labs Inc. All Rights Reserved.]

– Supports Graphics 2.0


local centerX = display.contentCenterX

local centerY = display.contentCenterY

local _W = display.contentWidth

local _H = display.contentHeight

– Camera not supported on simulator.                    

local isXcodeSimulator = “iPhone Simulator” == system.getInfo(“model”)

if (isXcodeSimulator) then

local alert = native.showAlert( “Information”, “Camera API not available on iOS Simulator.”, { “OK”})    

end

local bkgd = display.newRect( centerX, centerY, _W, _H )

bkgd:setFillColor( 0.5, 0, 0 )

local text = display.newText( “Tap anywhere to launch Camera”, centerX, centerY, nil, 16 )

local sessionComplete = function(event)

local image = event.target

print( "Camera ", ( image and “returned an image” ) or “session was cancelled” )

print( "event name: " … event.name )

print( "target: " … tostring( image ) )

local s = display.contentWidth /  image.width

if image.height > image.width then

     s = display.contentHeight / image.height

end

if image then

– center image on screen

image.x = centerX

image.y = centerY

image:scale( s, s )

local w = image.width

local h = image.height

print( “w,h = “… w …”,” … h )

end

end

local listener = function( event )

if media.hasSource( media.Camera ) then

media.capturePhoto( { listener = sessionComplete } )

display.save( image , { filename=“TestImage1.png”, baseDir=system.DocumentsDirectory, isFullResolution=true, backgroundColor={0, 0, 0, 0} } )

else

native.showAlert(“Corona”, “Camera not found.”)

end

return true

end

bkgd:addEventListener( “tap”, listener )

[/lua]

Thanks again,

Matt.

Still cannot work out the issue here if someone could shed some light here it would be great. I think it has something to do with line 61 not 100% sure thought.

Thanks,

Matt.

Try moving the display.save() function between lines 55 and 56.

Rob

Hi Rob,

I’ve tried moving this line and I still seem to be getting the same result, I tried looking my my device gallery as well as doing two searches on my device which was “TestImage1” and “document directory” and still nothing so im not sure how to proceed here.

Thanks for the help,

Matt.

You are saving this to your app’s writable sandbox folder that we call system.DocumentsDirectory.  If you’re doing this in the Simulator, you can do File->Show Project Sandbox which will open a folder with a bunch of cryptic looking file names.  Just double click on the selected one, then on the folder inside it called Documents.  Your image should be there.

If you are doing this on device, I’m not sure of a good way on Android to see this.  On iOS  you can use Xcode to view the files in the sandbox.

Rob

Hi Rob,

So is there not a method that will allow me to save the images that are being taken to a default “camera” folder in either iOS or Android. So it would save to the same place that the default camera app on the device saves to or even better an custom folder named after the app. 

Thanks again,

Matt.

See: https://docs.coronalabs.com/api/library/media/save.html

I have realised that by restarting my device the images appear to be saved i the gallery but if it isn’t restarted it doesn’t, which is odd. Does this mean that I can still call them without restarting the device?

Thanks for the help,

Matt.

Sometimes devices just need rebooted.  I don’t think this is a specific issue with our software and saving images.  I just had to reboot my iPhone because iMessage stopped sending to people. 

I would consider this a transient issue unless it happens again.

Rob

Still cannot work out the issue here if someone could shed some light here it would be great. I think it has something to do with line 61 not 100% sure thought.

Thanks,

Matt.

Try moving the display.save() function between lines 55 and 56.

Rob

Hi Rob,

I’ve tried moving this line and I still seem to be getting the same result, I tried looking my my device gallery as well as doing two searches on my device which was “TestImage1” and “document directory” and still nothing so im not sure how to proceed here.

Thanks for the help,

Matt.

You are saving this to your app’s writable sandbox folder that we call system.DocumentsDirectory.  If you’re doing this in the Simulator, you can do File->Show Project Sandbox which will open a folder with a bunch of cryptic looking file names.  Just double click on the selected one, then on the folder inside it called Documents.  Your image should be there.

If you are doing this on device, I’m not sure of a good way on Android to see this.  On iOS  you can use Xcode to view the files in the sandbox.

Rob

Hi Rob,

So is there not a method that will allow me to save the images that are being taken to a default “camera” folder in either iOS or Android. So it would save to the same place that the default camera app on the device saves to or even better an custom folder named after the app. 

Thanks again,

Matt.

See: https://docs.coronalabs.com/api/library/media/save.html

I have realised that by restarting my device the images appear to be saved i the gallery but if it isn’t restarted it doesn’t, which is odd. Does this mean that I can still call them without restarting the device?

Thanks for the help,

Matt.

Sometimes devices just need rebooted.  I don’t think this is a specific issue with our software and saving images.  I just had to reboot my iPhone because iMessage stopped sending to people. 

I would consider this a transient issue unless it happens again.

Rob