In the sample code that comes with Corona demonstrating the camera example
https://github.com/coronalabs/samples-coronasdk/blob/master/Media/Camera/main.lua
I was able to compile the code to an .apk, install in on my mobile device and successfully take a photo.
The sample code only DISPLAYS the image BUT I want to SAVE the image with a filename of my choice.
I am sure this is the snippet given at the end of this post, takes the photo and displays it and that the file is linked to the local variable called ‘image’.
The question is, how do it save it as a image file like ‘my_image.jpg’ in the mobile sdcard.
I found a line of code at the forum URL
display.save(photoGroup, "image.jpg", storeDirectory)
Will it work if I replace the keyword ‘display’ with ‘image’ to work with the code below? Or is there another command for that? I don’t understand the purpose of the variable ‘photoGroup’.
image.save(photoGroup, "my\_image.jpg", storeDirectory)
The snippet that takes the photo is given below.
-- Called when media.capturePhoto() finishes. If we get a photo back, display it. local displayedPhoto = nil local sessionComplete = function(event) local image = event.target -- If we got an image back, display some information about it, and fit it -- to the screen. if ( image ) then print( "media.capturePhoto() returned an image!" ) print( "event.target: ", image.\_properties) print( "Image resolution: ".. image.width .. "x" .. image.height ) -- Delete previous photo if we've displayed one. if ( displayedPhoto ) then displayedPhoto:removeSelf() end displayedPhoto = image -- Center the image on the screen. image.x = centerX image.y = centerY -- Resize the image to fit the screen. local diffX, diffY = image.width - \_W, image.height - \_H local scaleFactor = 1 if ( diffX \> diffY ) then scaleFactor = \_W / image.width else scaleFactor = \_H / image.height end image:scale( scaleFactor, scaleFactor ) -- Bring instruction text to the foreground. if ( displayText ) then displayText:toFront() end else print( "media.capturePhoto() was canceled." ) end end
UPDATE:
I have inserted the following code at line 12 and it saves the file BUT the file name is being saved as “Picture1.jpg” and subsequent pictures being saved as “Picture2.jpg” etc. even though I have specified the filename as “CamerShot.jpg”.
-- save image to file local filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" } media.show( media.Camera, onComplete, filePath )
How do I save the file according to the filename that I have specified.