How to add a capture function in the game

I know i should use the command below to open the camera

local onComplete = function( event )

    print( “Returned from camera view.” )

end

if media.hasSource( media.Camera ) then

    media.show( media.Camera, onComplete )

else

    native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

but what i want to know is how to save the photo i captured?

For example, save a photo to my default photo-album with the name image_01

please help~~ 

Hi Ryan,

Please inspect the Corona sample project located inside your local Corona application folder:

CoronaSDK > SampleCode > Media > Camera

Best regards,

Brent Sorrentino

I know that sample code,

But I just want to save the photo captured to my photoalbum, I tried the sample code, it can only capture, but not save.

I want to save the photo, change the photo name, and upload to the internet

Hi Ryan,

Do you want to only save the photo to a directory, but not to the photo album? In that case, you should explore the display.save() function:

http://docs.coronalabs.com/api/library/display/save.html

To rename it, you’ll probably want to use os.rename(), documented here:

http://docs.coronalabs.com/api/library/os/rename.html

Best regards,

Brent

How about is I just wanna save the photo to my photo album,say Iphone 4s

local onComplete = function( event )

    print( “Returned from camera view.” )

    local photo = event.target

    local baseDir = system.DocumentsDirectory

    photo.x = display.contentWidth/2

    photo.y = display.contentHeight/2

    photo.height= 480

    photo.width= 320

    display.save(photo, “entireScreen.jpg”, baseDir )

    

end

if media.hasSource( media.Camera ) then

    media.show( media.Camera, onComplete )

    

else

    native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

anything I need to change for the code above?

Hi Ryan,

“display.save()” will not save to the photo album, only to a file. For photo album saving, you should use “display.capture()” instead, and set the “saveToPhotoLibraryFlag” boolean flag to true.

http://docs.coronalabs.com/api/library/display/capture.html

Great, I fix the problem, thank you so much.

And now,  I have one more question,

If I want to upload a photo to google(As google has the function of finding photo’s name,say the photo is about balloon, then the search engine will use balloon as key word to search)

I would like to ask How can I get the name that google generate from my photo

For example, when a upload a photo about a book,

I want to get the output from google search engine(say books)

Hi Ryan,

Which method are you using at this time, display.save() or display.capture()? Can I see a bit of your current code so I can advise better?

Brent

here is my code…

I still use display.save() as I just need to upload to photo

– 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 onComplete = function( event )

    print( “Returned from camera view.” )

    local photo = event.target

    local baseDir = system.TemporaryDirectory

    display.save(photo, “entireScreen.jpg”, baseDir )

    photo.x = display.contentWidth/2

    photo.y = display.contentHeight/2

    photo.height= 340

    photo.width= 230

    

screenGroup:insert(photo)    

    

    

end

addcamera = function()

    local ui = require(“ui”)  --retake

    local retake =function(event)

            if event.phase ==“release” then

                

                    storyboard.gotoScene(“startmenu”,changeSceneEffectSetting)

                    storyboard.removeScene(“camera”)

                

            end

    end

    

    

    local ui = require(“ui”)  --upload

    local upload =function(event)

            if event.phase ==“release” then

                   — I want to add command here to upload to google image(and also wanna get the result photo name)

            end

    end

        RETAKE = ui.newButton{

        defaultSrc = “CoverButtoncopy.png”,

        defaultX=232,

        defaultY=68,

        overSrc = “CoverButtoncopy.png”,

        overX=232,

        overY=68,

        onEvent = retake,

        text =“RETAKE”,

        size = 40,

}

RETAKE.x = 160

RETAKE.y = 40

screenGroup:insert(RETAKE)

        UPLOAD = ui.newButton{

        defaultSrc = “CoverButtoncopy.png”,

        defaultX=232,

        defaultY=68,

        overSrc = “CoverButtoncopy.png”,

        overX=232,

        overY=68,

        onEvent = upload,

        text =“UPLOAD”,

        size = 40,

}

UPLOAD.x = 160

UPLOAD.y = 440

screenGroup:insert(UPLOAD)

end

Hi Ryan,

Once the file is saved to the device via display.save(), you can rename it using “os.rename()” to whatever you think is appropriate.

http://docs.coronalabs.com/api/library/os/rename.html

Then, you can upload it via the network library:

http://docs.coronalabs.com/api/library/network/index.html

Once it’s uploaded, we have no control over what Google does with it, or anything related to search engines and such.

Hope this helps,

Brent

Brent,

actually, I want my game has the function similar to the apps"google goggle"
I want to capture and items(in my game, food) then the program will automatically generate the name of

the photo… very similar to the “google goggle”, so can you help me with this, and give me some advices?

As I am an university student, I am now doing this as my Final Year Project. Please help

Hi Ryan,

I’m not sure how “Google Goggle” works, but there are no kind of “recognition” algorithms in Corona to attempt to interpret a snapped picture and its contents. My best guess, for that Google Goggle app, is that the images are being uploaded to some server, processed/analyzed somehow, and then sent back down with some kind of tagging info or a new name. That would need to be handled via methods Corona doesn’t control.

Sorry I can’t be of more help,

Brent

Brent, I decide to give up this part at this moment.

I would like to now how to build a database at this moment.

I want a database to store photos and string

Let say, each time I need to use the database, i can get a set of photo and string from the database

then the user need to guess what is the photo about and type the answer/ choose
if the answer match the string, user will get 1 point, otherwise, retry…

this is my flow, hope that u will understand

also, i would also want to know how to build a connection between two device, say two iPhone…

after connection, they can send above game to each other,

when i want is that, one user can upload photo and string to the database, and the another one get the photo from the database and guess what the photo about,

actually, the photo may be blurred/enlarge/diminish or something else…

this is a game to guess the photo

for multiplayer,  they can create and send 

single player, just download from the database

Thanks for helping me a lot…

Hi Ryan,

I’ll try to guide you to the correct places for your questions:

Q) “I would like to now how to build a database at this moment.

A) I can refer you to this section in Corona University, which contains tutorials and such on the topic:

http://www.coronalabs.com/resources/tutorials/data-files-and-strings/

Q) “I would also want to know how to build a connection between two device, say two iPhone…

A) You may want to investigate the Together plugin for this (docs). Or, you could try to work out your own server setup, but that would be more ambitious.

Q) “actually, the photo may be blurred/enlarge/diminish or something else…

A) If you want to blur the image, you’ll need our Graphics 2.0 engine, but this is in beta now, currently for Pro and Enterprise users only. It will allow you to blur and do many other Photoshop-like filters and effects on images.

Best regards,

Brent

Brent,
 

I cannot get the answer, can you help me and guide me to the correct direction? (i hv give more detail in the following)

First, In my game, I want to show some photos when the user click the button(say start/next) and this process will keep going until the user click the button(say leave/cancel)

  1.  where can i store these photos, i want to know how to store these photos and store each one with an unique name. And i can update this “photo database” when i want to add some photos"

  2.  After i find some play to store the photos, how can I show them randomly in my apps
      (Actually, I want to know how to show it first, and solve the other part by myself)

Please help… I really need you guys help…

Hi Ryan,

This tutorial on updating app content (via network) may help you:

http://www.coronalabs.com/blog/2013/03/19/updating-mobile-game-content-in-runtime-guest-post/

Brent

Hi Ryan,

Please inspect the Corona sample project located inside your local Corona application folder:

CoronaSDK > SampleCode > Media > Camera

Best regards,

Brent Sorrentino

I know that sample code,

But I just want to save the photo captured to my photoalbum, I tried the sample code, it can only capture, but not save.

I want to save the photo, change the photo name, and upload to the internet

Hi Ryan,

Do you want to only save the photo to a directory, but not to the photo album? In that case, you should explore the display.save() function:

http://docs.coronalabs.com/api/library/display/save.html

To rename it, you’ll probably want to use os.rename(), documented here:

http://docs.coronalabs.com/api/library/os/rename.html

Best regards,

Brent

How about is I just wanna save the photo to my photo album,say Iphone 4s

local onComplete = function( event )

    print( “Returned from camera view.” )

    local photo = event.target

    local baseDir = system.DocumentsDirectory

    photo.x = display.contentWidth/2

    photo.y = display.contentHeight/2

    photo.height= 480

    photo.width= 320

    display.save(photo, “entireScreen.jpg”, baseDir )

    

end

if media.hasSource( media.Camera ) then

    media.show( media.Camera, onComplete )

    

else

    native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

anything I need to change for the code above?