Why are 2 images saved with this code?

I am trying to take a picture and save it to the album. It saves one correct in the Pictures folder on my Galaxy Note 5 and then saves a smaller portion of the image as well.

Thanks,

Warren

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) photo:removeSelf() photo = nil end local function btnCameraButtonEvent( event ) if ( "ended" == event.phase ) then if ( media.hasSource( media.Camera ) ) then local random = math.random local R2 = math.random( 1000, 9999 ) local File2 = "pic" .. os.time() .. R2 .. ".jpg" composer.setVariable( "PhotoName", File2 ) media.capturePhoto( { listener = onComplete } ) else native.showAlert( "Error", "This device does not have a camera.", { "OK" } ) end end end

Have you accidentally added two listeners to fire your btnCameraButtonEvent listener?

An easy way to tell would be:

local function btnCameraButtonEvent( event )    print ("Entering btnCameraButtonEvent...")    if ( "ended" == event.phase ) then       ... the rest as before    end    print ("Exiting btnCameraButtonEvent...") end

Hi Warren,

You’re calling both display.save() and media.save(), thus 2 saved images.

Brent

Have you accidentally added two listeners to fire your btnCameraButtonEvent listener?

An easy way to tell would be:

local function btnCameraButtonEvent( event )    print ("Entering btnCameraButtonEvent...")    if ( "ended" == event.phase ) then       ... the rest as before    end    print ("Exiting btnCameraButtonEvent...") end

Hi Warren,

You’re calling both display.save() and media.save(), thus 2 saved images.

Brent