Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Saving camera picture
Started by Vasu Feb 12 2012 05:34 AM

- - - - -
38 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Vasu

[GLOBAL: userInfoPane.html]
Vasu
  • Observer

  • 11 posts
  • Corona SDK

Hi Guys,

Thanks for an amazing SDK. Having fun so far.

Regarding question. My current setup for taking pictures include following.

1. Capture image using media.show( )
2. [I want to avoid this] Once image is captured, do a display.save() to take a screenshot.

For #2, is there a way I can tell media.show() to save image in a temp or documents directory? Doing a screenshot is giving me very low quality pictures and I want to depend on the camera quality than screenshotting. Is it possible?
thanks

uid: 7499 topic_id: 21784 reply_id: 321784


[TOPIC: post.html]
#2

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

We've recently added the option to media.show() to save to a file in daily build #724. It's not documented yet since it is fairly new, but what you would do is this...

local onComplete = function(event)   if event.completed then      -- Camera shot was successfully taken.   else      -- User canceled out.   endendlocal filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" }media.show( media.Camera, onComplete, filePath )


Adding that 3rd argument tells media.show() to save to file instead of displaying the camera shot as a display object. The advantage being that the camera shot will be saved at full camera resolution, which display.save() cannot do since it is limited to screen resolution. Also, the Lua listener's "event.target" property will be set to nil in this case. If you omit the 3rd file argument, then media.show() will do the old behavior.

One more thing, this feature is currently only supported on iOS and Android. It is not supported on the Corona Simulator yet.

I hope this helps!
uid: 32256 topic_id: 21784 reply_id: 86497


[TOPIC: post.html]
#3

Vasu

[GLOBAL: userInfoPane.html]
Vasu
  • Observer

  • 11 posts
  • Corona SDK

Awesome. Thanks a lot. Just the thing I was searching for.

thanks
uid: 7499 topic_id: 21784 reply_id: 86501


[TOPIC: post.html]
#4

Vasu

[GLOBAL: userInfoPane.html]
Vasu
  • Observer

  • 11 posts
  • Corona SDK

On iOS, this works pretty good.

I am having hard time getting this to work on Android. Do I have to do anything special on Android?

thanks

I tried both of these:
local photo_name = "photo_new.jpg"
--local filePath = { baseDir = system.DocumentsDirectory, filename = photo_name }
local filePath = system.pathForFile(photo_name, system.DocumentsDirectory)
media.show(media.Camera, stageImage, filePath)
uid: 7499 topic_id: 21784 reply_id: 89717


[TOPIC: post.html]
#5

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

This definitely works on Android. Perhaps you forgot to set the "android.permission.CAMERA" permission in your build.settings file? Please see sample app "Media\Camera" that is included with the Corona SDK for more details.
uid: 32256 topic_id: 21784 reply_id: 89718


[TOPIC: post.html]
#6

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

cant seem to get this to work on a device, the image never shows up. code is like this:

local onComplete = function(event)	if event.completed then		event.target:removeSelf() -- remove the image grab from camera		local img = display.newImage("CameraShot.jpg", system.DocumentsDirectory) -- display image that was saved		img.x = contentWidth/2		img.y = contentHeight/2	else		-- User canceled out	endendlocal filePath = { baseDir = system.DocumentsDirectory, filename = "CameraShot.jpg" }media.show( media.Camera, onComplete, filePath )
uid: 17969 topic_id: 21784 reply_id: 99219


[TOPIC: post.html]
#7

Vasu

[GLOBAL: userInfoPane.html]
Vasu
  • Observer

  • 11 posts
  • Corona SDK

borgb,

not sure if it is something to do with the version. Mine works perfectly.

I have something like this:


local staging_image = display.newImage(photo_name, system.TemporaryDirectory )
staging_image.x = display.contentWidth/2
staging_image.y = display.contentHeight/2
group:insert(staging_image)


Also, any reason why you are removing the event?
uid: 7499 topic_id: 21784 reply_id: 99431


[TOPIC: post.html]
#8

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

as far as I have understood it the event is a screengrab of the camera and I dont really need that. I have tried without removing it but nothing gets saved then either. If I do display.save it works as it should and I can save the image and all. but would like a little bigger file to work with.

I am running 776 daily build atm.
uid: 17969 topic_id: 21784 reply_id: 99436


[TOPIC: post.html]
#9

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

borgb,

What is the make and model of the Android device you are using?

Also, can you try running sample app "media/camera" that is included with the Corona SDK on your Android device to see if it works?

If the sample app does not have access to the camera, then it will display a warning message indicating so. It checks for camera support by calling the Lua function...
media.hasSource(media.Camera)

uid: 32256 topic_id: 21784 reply_id: 99564


[TOPIC: post.html]
#10

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

not Android, trying it out on Iphone 4s.

I have access to the camera, no problem. I can take a photo and use display.save and get a file from that I can use. I guess it would be good enough but I would really like the full resolution photo file as well. Or at least that the image that gets taken also gets saved in the users photo album as a normal photo would.
uid: 17969 topic_id: 21784 reply_id: 99571


[TOPIC: post.html]
#11

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Calling media.show() with a file path like below will save the image to file at full resolution. If you want to then display the saved photo at full resolution, then you will need to call display.newImage() function as shown below...

local onComplete = function(event)   if event.completed then      -- Camera shot was successfully taken.      -- Display at full resolution by passing in true.      display.newImage("CameraShot.jpg", system.TemporaryDirectory, true)   else      -- User canceled out.   endendlocal filePath = { baseDir = system.TemporaryDirectory, filename = "CameraShot.jpg" }media.show( media.Camera, onComplete, filePath )


The full resolution option for the display.newImage() is documented via the link below...
http://developer.anscamobile.com/reference/index/displaynewimage

Please note that the displayed image will still be capped based on the max OpenGL texture size limit, which is typically 2048x2048 pixels on most iOS devices... but the image file will be the original size of the photo in case you want to upload it somewhere.

Also note that the media.show() function will not save to file in the Corona Simulator. We have not added support to the simulator yet, but this feature does work on iOS and Android.
uid: 32256 topic_id: 21784 reply_id: 99586


[TOPIC: post.html]
#12

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

@Joshua Quick

Awesome, that worked! Thanks! Im guessing it worked all the time really, I just though I only got the screenshot and not the file. Still got alot to learn! :)

Is there also a way to save the image to the users photo album?
I saw there was a: object = display.captureScreen( saveToAlbum ) but that would only save a screenshot right?
uid: 17969 topic_id: 21784 reply_id: 99714


[TOPIC: post.html]
#13

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Correct. The only way to save images to the photo library in Corona is via our screenshot APIs...
display.captureScreen(true)

display.capture(myDisplayObject, true)


We do have a feature request written up to be able to export an image file to the photo library so that you can maintain the full resolution of the image. I believe that is the feature that you are after, right? It's on our to-do list, but it's not scheduled yet.
uid: 32256 topic_id: 21784 reply_id: 99849


[TOPIC: post.html]
#14

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

Great, thanks for the reply. I am wondering if I should only let the user import from photo album and just take the photo with the camera as usual. Guess I will try and see abit more and decide when its all done, maybe you will get there before me :)

Anyway, was playing abit with taking photos and noticed that no matter if I took it in landscape or portrait it would always report it back with the same image width. is there a way to detect which way the user took the image? I would like to rotate the image so its the right way like when you view them in the photo album. This also seems to be the same when importing from album.. but havent tested much there yet.
uid: 17969 topic_id: 21784 reply_id: 99867


[TOPIC: post.html]
#15

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

The orientation of the photo is stored in the image file's EXIF metadata. There is a bug in the iOS version of Corona where the EXIF orientation is ignored when loading images. The Android version of Corona does not have this problem.

Unfortunately, the only work-around at the moment is to not save the camera shot to file and show the image onscreen instead... which means that you will lose the full resolution of the image within Corona.
uid: 32256 topic_id: 21784 reply_id: 99938


[TOPIC: post.html]
#16

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

ok, hope you get that fixed by the time Im ready to release then ;) Else I have to either put it on hold or go with the low res version. If I only let them import from album they will at least have a copy of the high res for themselves.

Thanks again for the quick replys!
uid: 17969 topic_id: 21784 reply_id: 100002


[TOPIC: post.html]
#17

alabelson

[GLOBAL: userInfoPane.html]
alabelson
  • Observer

  • 2 posts
  • Corona SDK

Any way you can save it to the file name of the file that the Camera sets it to. Or if you choose an image from the Photo Library, save it to that name? Or at least get the file name. I want to upload the photo to a server, but have it named as the user had it on their phone.
uid: 60471 topic_id: 21784 reply_id: 101184


[TOPIC: post.html]
#18

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

alabelson,

The selected photo file name is currently unaccessible in Corona. Even if we did provide you the path and file name to the photo, your app would not have permission to overwrite files owed by other apps. In this case, the Camera is its own app and iOS would definitely NOT allow this.

I've found on Android, this is hit or miss. On some phones I had permission to overwrite the file and others I didn't. The inconstancies across different Android devices just boggles my mind. This is partly why we implemented our own camera view in Corona.
uid: 32256 topic_id: 21784 reply_id: 101341


[TOPIC: post.html]
#19

alabelson

[GLOBAL: userInfoPane.html]
alabelson
  • Observer

  • 2 posts
  • Corona SDK

Thank you for your response.

I'm not looking to overwrite the file on the actual device. But if my app lets someone choose a photo from their photo library to upload to a server, I'd like to save the image on the server side with the same name it is on the device. Same goes for someone that just takes a picture. I'd like to be able to upload that picture with the same name (i.e. IMG_0194.JPG) instead of having to ask the user to rename it, or generating a name dynamically.
uid: 60471 topic_id: 21784 reply_id: 101347


[TOPIC: post.html]
#20

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Fair enough. I've written this up as a feature request to retrieve the original name of the photo. The only limiting factor here is iOS, which may not give you access to that file's name due to sandboxing. In which case, the only work-around is to retrieve the file's EXIF description which of course won't match the file name, but at least it's something.
uid: 32256 topic_id: 21784 reply_id: 101352


[TOPIC: post.html]
#21

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

An easy way to get orientation as well from the exif data would be great , or fix that orientaion bug within ios, whatever is fastest ;)
uid: 17969 topic_id: 21784 reply_id: 104161


[TOPIC: post.html]
#22

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

An easy way to get orientation as well from the exif data would be great , or fix that orientaion bug within ios, whatever is fastest ;)
uid: 17969 topic_id: 21784 reply_id: 104162


[TOPIC: post.html]
#23

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

Any news regarding the orientaion bug of full resolution images from camera?
uid: 17969 topic_id: 21784 reply_id: 107799


[TOPIC: post.html]
#24

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

It's still on the to-do list and it is flagged "important", but unfortunately there are other bugs flagged with a higher priority that are in the way. I'm sorry to say this bug will likely not get fixed by the upcoming release. Just being honest with you. But I will bug our iOS developers about this again.
uid: 32256 topic_id: 21784 reply_id: 107944


[TOPIC: post.html]
#25

borgb

[GLOBAL: userInfoPane.html]
borgb
  • Contributor

  • 291 posts
  • Corona SDK

@Joshua: I understand, thanks for the update. Crossing fingers then that there will be an update soon but will get everything else ready at least. Have a couple of apps in the pipeline that is waiting for this functionality :)
uid: 17969 topic_id: 21784 reply_id: 108035



[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]