Get back to camera after taking photo (and saving photo to photo library)

Hi,

With below code I can take photo and save it into library. What I’d like to do is to have the camera behave like the native app that comes with phone. I mean I can take photo and the photo get saved into the album and I can still keep using the camera.

local function onComplete( event ) local photo = event.target if photo then photo.x = display.contentWidth/2 photo.y = display.contentHeight/2 end display.save(photo, "myphoto.png", system.TemporaryDirectory) media.save("myphoto.png", system.TemporaryDirectory) end if media.hasSource( media.Camera ) then media.capturePhoto( { listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end

Could someone please share the code to do that? Thank you.

So Lin

Have you considered calling media.capturePhoto() right after you do media.save?

Hi Rob,

I tried it and it works only for the second time, after that it won’t return to Camera.

Thank you.

So Lin

Look like the listener function is not fired during second shot. Any other suggestions?
Thank you.
So Lin

Try:

local function onComplete( event )     local photo = event.target     if photo then         photo.x = display.contentWidth/2         photo.y = display.contentHeight/2     end     display.save(photo, "myphoto.png", system.TemporaryDirectory)     media.save("myphoto.png", system.TemporaryDirectory)     timer.performWithDelay(10, function() media.capturePhoto( { listener=onComplete } ); end ) end

Hi Rob,

That works. Could you explain why? and one more thing, how can we save photo into the album automatically without the need to press the tick (on android) and Use photo (on ios)?

Thank you so much for your help.

So Lin

Its a matter of being in the same call back you’re trying to re-use.  The timer lets the previous callback function finish and clean itself up.

As for the auto-save, we are using OS controls and offer what they give us.

Rob

Hi Rob,

What puzzle me the most is that when I just use media.capturePhoto alone (without wrapping it inside function()), it doesn’t work. For auto-save, do you mean that we can’t do it? Thank you.

So Lin

This is baffling. Rob, can you explain why you put this code:

timer.performWithDelay(10, function() media.capturePhoto( { listener=onComplete } ); end )

Inside the call-back function for media.capturePhoto?!?!? It looks like media.capturePhoto will cause infinite looping!

Please explain what’s going on here! I am having camera trouble, too.

Hey @mimetic, the previous poster wanted the camera app to fire back up immediately after taking one photo like the default camera app behaves.  Our control is more like one you would use for social networks were you take one photo then your app does something with the photo.  So in effect, it is infinite looping.   It’s done in a timer because when you try and call something thats in the middle of handling an event you sometimes need to give the listener a chance to complete.

Rob

Aha. Thank you.

Can you clarify your camera control? I am using object.fill to make a live view of the camera, but when I use media.capturePhoto to take a picture, the live view stops. I think it might resume if I had other objects on top of the live view that had enterFrame events, but that shouldn’t be necessary.

I’m using display.setDrawMode( “forceRender” ), but that isn’t sufficient.

I’m not sure I can since I’m not building a camera app.  As for the issue you are running into, I suspect it’s two separate processes fighting for control of the camera.  The media.capturePhoto() is using an OS control to handle the camera and I’m guessing that its interfering with our direct access to the camera.  In face I’m surprised that media.capturePhoto() works at all with the app already using the camera.  I don’t know if our object fill use of the camera can be hardened or not.  We added it as an experiment and to mess around with Augmented Reality.  I don’t think it was conceived to build a functioning camera app.  It’s pumping a video feed into the fill and isn’t designed for photo capture.

Rob

Rob, I guessed it was pushing a video feed in. However, it’s the only way to have a live-view camera. And, yes, you can build a camera out of it (with lo-res and poor quality), but good enough for kids.

I wanted to offer the ability to take a real photo to get better quality — if I could simply “fire” the camera without using the built-in interface, that’d cool, because then I could use my live-view (with a grid, etc.), but fire off real photos.

-D
 

Have you considered calling media.capturePhoto() right after you do media.save?

Hi Rob,

I tried it and it works only for the second time, after that it won’t return to Camera.

Thank you.

So Lin

Look like the listener function is not fired during second shot. Any other suggestions?
Thank you.
So Lin

Try:

local function onComplete( event )     local photo = event.target     if photo then         photo.x = display.contentWidth/2         photo.y = display.contentHeight/2     end     display.save(photo, "myphoto.png", system.TemporaryDirectory)     media.save("myphoto.png", system.TemporaryDirectory)     timer.performWithDelay(10, function() media.capturePhoto( { listener=onComplete } ); end ) end

Hi Rob,

That works. Could you explain why? and one more thing, how can we save photo into the album automatically without the need to press the tick (on android) and Use photo (on ios)?

Thank you so much for your help.

So Lin

Its a matter of being in the same call back you’re trying to re-use.  The timer lets the previous callback function finish and clean itself up.

As for the auto-save, we are using OS controls and offer what they give us.

Rob

Hi Rob,

What puzzle me the most is that when I just use media.capturePhoto alone (without wrapping it inside function()), it doesn’t work. For auto-save, do you mean that we can’t do it? Thank you.

So Lin