How to move a picture after photoCapture?

hello.

I am starting to use the camera to take pictures.

I can take a picture and it shows in the center of the iPad.

(I am using the sample code included in Corona)

Inside of this function

local sessionComplete = function(event)  

I see that event.target is the image

local image = event.target

Now to me… image is a variable.

so later in the code I want to “move” that variable like

image.rotation = 45

but I just can’t, because the image is “local” to the function

If I use the local on top of the code, the function won’t work

if I put local image = event.target on top of the code ( event is “nill”

I just don’t get it

how can I move, rotate, scale in general manipulate that image once is taken?

Thanks

Outside of the listener function, define a variable that you want to use for this.  Let’s call it “myImage”.  Then inside your listener function assign your event.target (the display object) to your variable:

myImage = event.target

After that  you can use myImage anywhere that myImage is scoped for.

Rob

Hi Rob, I have no idea what to do… it keeps giving me errors

this is the complete code

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) -- Camera not supported on simulator.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model") if (isXcodeSimulator) then &nbsp;&nbsp; &nbsp; local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})&nbsp;&nbsp; &nbsp; end -- local bkgd = display.newRect( centerX, centerY, \_W, \_H ) bkgd:setFillColor( 0.5, .6, .9 ) local text = display.newText( "Tap anywhere to launch Camera", centerX, centerY, nil, 16 ) --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local sessionComplete = function(event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; --local myImage = event.target -- \<\<\<\<\< THIS IS THE ONLY PLACE THAT WORKS &nbsp;&nbsp; &nbsp;if myImage then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- center image on screen &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage.x = centerX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage.y = centerY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage:scale (.6, .6) &nbsp;&nbsp; &nbsp;end end --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local listener = function( event ) &nbsp;&nbsp; &nbsp;if media.hasSource( media.Camera ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;media.capturePhoto( { listener = sessionComplete } ) &nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;native.showAlert("Corona", "Camera not found.") &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return true end bkgd:addEventListener( "tap", listener )

Where ever I put it it gives me error

Thanks for your help and patience

Victor

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local myImage -- Camera not supported on simulator.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model") if (isXcodeSimulator) then &nbsp;&nbsp;&nbsp;&nbsp; local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})&nbsp;&nbsp; &nbsp; end -- local bkgd = display.newRect( centerX, centerY, \_W, \_H ) bkgd:setFillColor( 0.5, .6, .9 ) local text = display.newText( "Tap anywhere to launch Camera", centerX, centerY, nil, 16 ) --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local sessionComplete = function(event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; myImage = event.target -- \<\<\<\<\< THIS IS THE ONLY PLACE THAT WORKS &nbsp;&nbsp;&nbsp; if myImage then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- center image on screen &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage.x = centerX &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage.y = centerY &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage:scale (.6, .6) &nbsp;&nbsp;&nbsp; end end local listener = function( event ) &nbsp;&nbsp;&nbsp; if media.hasSource( media.Camera ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; media.capturePhoto( { listener = sessionComplete } ) &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native.showAlert("Corona", "Camera not found.") &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return true end bkgd:addEventListener( "tap", listener )

You were close.

Rob

Thanks Rob. Now it works great!

Outside of the listener function, define a variable that you want to use for this.  Let’s call it “myImage”.  Then inside your listener function assign your event.target (the display object) to your variable:

myImage = event.target

After that  you can use myImage anywhere that myImage is scoped for.

Rob

Hi Rob, I have no idea what to do… it keeps giving me errors

this is the complete code

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) -- Camera not supported on simulator.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model") if (isXcodeSimulator) then &nbsp;&nbsp; &nbsp; local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})&nbsp;&nbsp; &nbsp; end -- local bkgd = display.newRect( centerX, centerY, \_W, \_H ) bkgd:setFillColor( 0.5, .6, .9 ) local text = display.newText( "Tap anywhere to launch Camera", centerX, centerY, nil, 16 ) --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local sessionComplete = function(event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; --local myImage = event.target -- \<\<\<\<\< THIS IS THE ONLY PLACE THAT WORKS &nbsp;&nbsp; &nbsp;if myImage then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- center image on screen &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage.x = centerX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage.y = centerY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;myImage:scale (.6, .6) &nbsp;&nbsp; &nbsp;end end --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local listener = function( event ) &nbsp;&nbsp; &nbsp;if media.hasSource( media.Camera ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;media.capturePhoto( { listener = sessionComplete } ) &nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;native.showAlert("Corona", "Camera not found.") &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return true end bkgd:addEventListener( "tap", listener )

Where ever I put it it gives me error

Thanks for your help and patience

Victor

local centerX = display.contentCenterX local centerY = display.contentCenterY local \_W = display.contentWidth local \_H = display.contentHeight local myImage -- Camera not supported on simulator.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model") if (isXcodeSimulator) then &nbsp;&nbsp;&nbsp;&nbsp; local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"})&nbsp;&nbsp; &nbsp; end -- local bkgd = display.newRect( centerX, centerY, \_W, \_H ) bkgd:setFillColor( 0.5, .6, .9 ) local text = display.newText( "Tap anywhere to launch Camera", centerX, centerY, nil, 16 ) --local myImage = event.target --\<-- Attempt to index global 'event' (a nil value) local sessionComplete = function(event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; myImage = event.target -- \<\<\<\<\< THIS IS THE ONLY PLACE THAT WORKS &nbsp;&nbsp;&nbsp; if myImage then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- center image on screen &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage.x = centerX &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage.y = centerY &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myImage:scale (.6, .6) &nbsp;&nbsp;&nbsp; end end local listener = function( event ) &nbsp;&nbsp;&nbsp; if media.hasSource( media.Camera ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; media.capturePhoto( { listener = sessionComplete } ) &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; native.showAlert("Corona", "Camera not found.") &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return true end bkgd:addEventListener( "tap", listener )

You were close.

Rob

Thanks Rob. Now it works great!