First time using media.capturePhoto() I have some doubts

Hi!

This is my first time using media.capturePhoto() api. I want to make a scene in my app where the user touches a button in the app menu and open the camera to take a photo of some surface. Then I wanted to reduce and multiply it in 9 images organized as the attached photo. Below those images would have 15 buttons that would change the color of the background square where the images will be multiplied. As I am a new programmer I do not have any type of experience with the use of the camera. I read the “Corona SDK > Sample Code> Media> Camera” but I do not really understand it yet.

Doubts:

* Can I use that same “Camera” example in my app and just change some things? How?

​* Can I use only the example code in the api page of media.capturePhoto() as a part of my scene?

* In which part of the scene (create>show>hide>destroy) I must use the function correctly to avoid memory

  leaks?

* It is better not to reduce or multiply the image just send it back and put my other objects in front to simulate 

​  it’s reduce/multiply?

I would like to know how to manipulate the captured photo as one more object in my scene.

Attachment info:

--Light gray is my backgroung

​–square Is what changes color when I touch one of the buttons

–9 white tiles is the reduce/multiply same captured image

​–rectangle is the color change buttons background

​–The 15 circles are my color change buttons

​Thanks in advance.

You can write such an app w/ Corona.

Whether you can start from the example… I guess, but you’re going to have to make a number of coding changes.

It really sounds more like you want somone to help you write this.  If so, you can post a job request here:

https://forums.coronalabs.com/forum/586-corona-jobs/

The effort for the example you’ve given is not insignificant (more than a few minutes), but at the same time not that big (less than 4 hours).

I’ve done very similar work for another community member, so if you do decide to post a job request, I’ll probably be able to help you.

@roaminggamer: Thanks for the fast answer. I would like to try to write it by myself. I want to develop the ability to gradually learn more about programming. If you can guide me where to start reading I would appreciate it.

I’d start by doing the following:

  • Skip composer.* (scenes) to start.  Make a standalone module based on the camera example that can:
    • Create the interfaces you need to take the pictures, edit them, view them, etc.
    • Destroy the interfaces and clean up.
    • Then…
  • Practice making basic composer.* skeletons, gradually working your way up to a framework with:
    • splash screen if you want one
    • menu screen
    • placeholder where the app will go
    • info screen if you want one
    • settings screen if you want one.
    • Be sure you clearly understand how the composer.* scene phases/callbacks/listeners work.
    • Then…
  • Copy the module(s) you wrote initially into your framework and start hooking them up.

At this point you should be pretty close to what you want.

I have lots of examples of many things, including composer frameworks:

One more note.  For general learning,reading, and reference:

@roaminggamer – Thanks for your quick response. Looks very good material, I will study it carefully. I have 80% of my App already made. I have tested it on 26 different Android devices including a ‘Live Wire’ Android device from the government program with no problems. I did everything by adjusting for my needs what I learned from the Getting Started guide. Now, to have my App 100% I only need to learn how to handle objects that are the result of media.capturePhoto. I searched all over google, youtube, the Corona forum, look up under my bed too but did not find anything that could clarify my doubt about the handling of those objects. So I decided to create this topic to see if someone clarified my mind and to be able to go ahead with this project and others that I have already planned. I really want to learn because I would like to do business with this and be a client of Corona Enterprise in the not too distant future.

Button that opens the camera:

-- camera Button camButton = widget.newButton( { width = 66, height = 66, defaultFile = "images/buttons/cam.png", overFile = "images/buttons/cam-over.png", } ) -- Center the cam button camButton.x = display.contentWidth-615 camButton.y = display.contentHeight-488 sceneGroup:insert( camButton ) camButton:addEventListener( "touch", camButtonTouch )

Function:

 -- cam button function local function camButtonTouch( event ) if ( event.phase == "began" ) then if media.hasSource( media.Camera ) then media.capturePhoto( { listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end elseif ( event.phase == "ended" ) then print( "camera is ready to take a photo" ) end return true end -- camera function local function onComplete( event ) local photo = event.target print( "photo w,h = " .. photo.width .. "," .. photo.height ) end

The scene opens, when I touch the camera widget button (Corona simulator)  I get the alert that says “Corona”, “This device does not have a camera.” But after clicking ok I can not leave the scene, neither the return button works, anywhere I touch the alert returns again and again. The only way to return for menu is relaunching the app.

Any help?

Thanks in advance

Any suggestions?

Sorry, very busy.  Just haven’t got time right now to dig into code posts.

You could, zip up your whole project, share it here so someone can look at it and give you feedback.

Note, You left out details:

  • Version of Corona you’re using: ex: I’m using 2017.3032 right now.
  • What device(s) you tested on.
  • What version of the OS (on device) you tested on.
  • If on Android, What does your build.settings file permissions section look like?
  • etc.

Thanks for your answer.

I am working hard, reading a lot, practicing a lot. Step by step I clarify my doubts. If I can not solve my problem I will prepare the project to upload it with the information you ask me.

Thanks again for your time.

Hi.  You keep writing posts saying " I have some doubts".  My guess is English is not your first language and you’re translating your questions.  That is cool, but let me give you a small correction.

The phrase you are seeking is, " I have some questions".

Cheers,

Ed

I’m not picking on you here, just thought you might want to know. :)  

You are correct that English is not my first language. I’m learning, and sometimes struggle with grammar, especially when trying to compose a message. I want to thank you for all of the help you provide for me, and all others like me, who come to forum in search of the knowledge that professionals such as yourself are able to provide.

You can write such an app w/ Corona.

Whether you can start from the example… I guess, but you’re going to have to make a number of coding changes.

It really sounds more like you want somone to help you write this.  If so, you can post a job request here:

https://forums.coronalabs.com/forum/586-corona-jobs/

The effort for the example you’ve given is not insignificant (more than a few minutes), but at the same time not that big (less than 4 hours).

I’ve done very similar work for another community member, so if you do decide to post a job request, I’ll probably be able to help you.

@roaminggamer: Thanks for the fast answer. I would like to try to write it by myself. I want to develop the ability to gradually learn more about programming. If you can guide me where to start reading I would appreciate it.

I’d start by doing the following:

  • Skip composer.* (scenes) to start.  Make a standalone module based on the camera example that can:
    • Create the interfaces you need to take the pictures, edit them, view them, etc.
    • Destroy the interfaces and clean up.
    • Then…
  • Practice making basic composer.* skeletons, gradually working your way up to a framework with:
    • splash screen if you want one
    • menu screen
    • placeholder where the app will go
    • info screen if you want one
    • settings screen if you want one.
    • Be sure you clearly understand how the composer.* scene phases/callbacks/listeners work.
    • Then…
  • Copy the module(s) you wrote initially into your framework and start hooking them up.

At this point you should be pretty close to what you want.

I have lots of examples of many things, including composer frameworks:

One more note.  For general learning,reading, and reference:

@roaminggamer – Thanks for your quick response. Looks very good material, I will study it carefully. I have 80% of my App already made. I have tested it on 26 different Android devices including a ‘Live Wire’ Android device from the government program with no problems. I did everything by adjusting for my needs what I learned from the Getting Started guide. Now, to have my App 100% I only need to learn how to handle objects that are the result of media.capturePhoto. I searched all over google, youtube, the Corona forum, look up under my bed too but did not find anything that could clarify my doubt about the handling of those objects. So I decided to create this topic to see if someone clarified my mind and to be able to go ahead with this project and others that I have already planned. I really want to learn because I would like to do business with this and be a client of Corona Enterprise in the not too distant future.

Button that opens the camera:

-- camera Button camButton = widget.newButton( { width = 66, height = 66, defaultFile = "images/buttons/cam.png", overFile = "images/buttons/cam-over.png", } ) -- Center the cam button camButton.x = display.contentWidth-615 camButton.y = display.contentHeight-488 sceneGroup:insert( camButton ) camButton:addEventListener( "touch", camButtonTouch )

Function:

 -- cam button function local function camButtonTouch( event ) if ( event.phase == "began" ) then if media.hasSource( media.Camera ) then media.capturePhoto( { listener=onComplete } ) else native.showAlert( "Corona", "This device does not have a camera.", { "OK" } ) end elseif ( event.phase == "ended" ) then print( "camera is ready to take a photo" ) end return true end -- camera function local function onComplete( event ) local photo = event.target print( "photo w,h = " .. photo.width .. "," .. photo.height ) end

The scene opens, when I touch the camera widget button (Corona simulator)  I get the alert that says “Corona”, “This device does not have a camera.” But after clicking ok I can not leave the scene, neither the return button works, anywhere I touch the alert returns again and again. The only way to return for menu is relaunching the app.

Any help?

Thanks in advance

Any suggestions?

Sorry, very busy.  Just haven’t got time right now to dig into code posts.

You could, zip up your whole project, share it here so someone can look at it and give you feedback.

Note, You left out details:

  • Version of Corona you’re using: ex: I’m using 2017.3032 right now.
  • What device(s) you tested on.
  • What version of the OS (on device) you tested on.
  • If on Android, What does your build.settings file permissions section look like?
  • etc.