Someone started a topic in the newbie section, and I chimed in because I was coincidentally working on using the camera API in my app.
http://developer.anscamobile.com/forum/2011/02/03/camera-support
The bottom line is that, based on the original sample code below from http://developer.anscamobile.com/reference/video, I am trying to take the image and save it as a JPG/PNG in order to upload it to my server.
1 2 3 4 5 | local onComplete = function(event) local photo = event.target print( "photo w,h = " .. photo.width .. "," .. photo.height ) end media.show( media.Camera, onComplete ) |
If photo contains the image, how to I get to redisplay it at will? I tried background = display.newImage ( photo )but I got a "proxy" error. Also, I tried display.save to save it to a JPEG in the temporary directory, then using background=display.newImage.. to retrieve it, and the image quality is so blocky and low-resolution.
Is the Camera API really usable, am I doing it wrong? Please help!
Can't help you with the resolution thing, but you need to centre the image:
1 2 3 | photo.x = display.contentWidth/2 photo.y = display.contentHeight/2 display.save(photo, ....) |
Do a removeSelf after that if you don't want it visible straight away.
Then you can load it as a regular newImage.
Thank you, MarkHenryC. It's darn blurry, but at least it's centered. Hopefully they'll fix the resolution thing, it looks pretty bad.
Am aware of the issue - it bugs me too ! I'll c what we can do
c
Thanks for the response, Carlos. If you can throw it into an upcoming daily build, I would love to test it out.
I'm still tinkering with this issue to see if I can make a workaround, but I think the problem also lies with the display.save command.
I tried to give up on using the Camera (media.Camera) and went for the Photo Library (media.PhotoLibrary) instead. I mean, every iOS device has a Photo Library and not a camera, right? (Out of curiosity, what happens if you try to open the camera on a device that doesn't have one? Do we have a detector for that, perhaps one to be put in a system.getInfo("camera") result?
The image I chose showed up properly on screen on the device, but when it went to capture it, it did a poorly compressed copy of the upper-left corner of the screen.
I tried display.save(photo,... as well as display.save(display.getCurrentStage()... before removing the image properly displayed on my device, and they both produced the same crappy results in the final JPEG.
One thing of note is that the capture of display.getCurrentStage is 320x480 on my iPhone 4... I don't have an older device to test, but maybe it's working for older devices and just needs to be tweaked for the Retina display?
This is the issue I've been hacking away at the past few days. I have client that wants a camera and at this point I will need to switch to another API if this doesn't get resolved soon. At such a low resolution, the camera is pretty much a toy right now.
If I find anything I'll be sure to post it.
It is a known issue with Corona and we are looking at this as I type away...
C.
@Carlos, thanks for looking into this. Much appreciated.
I hope this can get resolved soon, this is one of the last two pieces of the puzzle for my game. I'm throwing everything but the kitchen sink into my first title.
the latest daily build has a fix for higher resolution jpeg image.
am going to fix for saving the entire display later today/tomorrow
c
Everyone stand back!
[start]
[happy dance]
[happy dance]
[happy dance]
[done]
ok. Carry on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | -- camera capture local onCameraComplete = function (event) local photo = event.target if photo then photo.x = display.contentWidth / 4; photo.y = display.contentHeigh / 4; photo:scale(0.5,0.5) display.save( display.currentStage, "imageCapture.jpg",system.DocumentsDirectory) debug ("Captured photo, dimensions: " .. photo.width .. "x" .. photo.height); photo:removeSelf() local alert = native.showAlert ("Thank you!","Your image has been captured.", { "OK" } ); else debug ("No photo was taken"); end end media.show(media.Camera, onCameraComplete); |
The code above works in my game using build 299, and the image looks great on my iPhone 4.
But I have a few things of note:
So, to clarify Carlos' announcement above, I'm not getting a higher-resolution image, but a higher-quality rendering and a complete image. I believe the resolution is due to my settings in config.lua.
I'm doing a screen capture instead of saving the contents of variable photo because I was getting even funkier results.
@BeyondTheTech:
I just tested it out on the iPhone 3G and it looks significantly better with the new build (I'm using build 300). It's not anywhere near the grainy, pixelated images I was getting before.
Also, your method of using display.currentStage when saving the image improved the image clarity and sharpness as well (as opposed to using display.save(event.target, "imageCapture.jpg", system.DocumentsDirectory). And using the scaling adjustments completely fixed every scaling issue I had.
Thanks So Much!! And Thanks to Ansca and Carlos too!
Here's the relevant parts of the code I'm using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | local t = event.target local scaleX, scaleY = display.contentScaleX, display.contentScaleY print("scaleX, scaleY: ", scaleX, scaleY) if scaleX ==.5 and scaleY == .5 then print("this is displaying on a retina display... iPhone 4G") t.x = display.contentWidth / 4 t.y = display.contentHeight / 4 t:scale(0.5,0.5) elseif scaleX == 1 and scaleY == 1 then print("this is displaying on an iPhone 3G.") --centering image t.x = display.viewableContentWidth/2 t.y = display.viewableContentHeight/2 else print("this is displaying on some other device.") --centering image t.x = display.viewableContentWidth/2 t.y = display.viewableContentHeight/2 end display.save( display.currentStage, newPhotoName,system.DocumentsDirectory) |
That's a neat trick, w2md. I always wanted to know how my app can more closely determine what device it's running on.
The iPad happens to return a value of 0.46875 (well, according to the Simulator so far), so you can choose to not grab from media.Camera (that the iPad doesn't have), but media.PhotoLibrary instead - every iOS device has one of those.
HOWEVER...
There appears to be another bug, or at least when I'm using media.PhotoLibrary on the iPad. If I cancel or tap out of the photo selection, my application appears to hang for a long time. It doesn't crash, but it's unusable for the app and would likely get rejected by Apple's review team.
I'd use the iPad value to hide the Camera import feature entirely, but we all know that the iPad 2 will be coming out and it will sport multiple cameras, so they'll likely be crying foul that they can't use the feature.
Back to square 2?
@BeyondtheTech
re:"There appears to be another bug, or at least when I'm using media.PhotoLibrary on the iPad. If I cancel or tap out of the photo selection, my application appears to hang for a long time"
I noticed that as well. The higher resolution is a marked improvement. The issue now is trying to capture the 512x384 size as it appears that is the largest it will allow at this time. I can easily capture the screen with the hi-res but I want the full 512.
Has anyone tried to add custom camera button, zoom, flash, front/back camera and HDR so it doesn't look like the standard camera app?
Is there a way to implement HDR with corona or is that feature not ready?
I'm curious about the camera too, can someone sum up all the bits and pieces of camera code so we get an updated and functional sample with the save to photo library implemented?
Do we have to use the "start screen" to launch the camera, can't it just go directly to the app and the just have a button that takes the user to a LightBox preview?
Video recording is not implemented in corona is it? From what I can understand is only audio recording available.
There appears to be another bug, or at least when I'm using media.PhotoLibrary on the iPad. If I cancel or tap out of the photo selection, my application appears to hang for a long time. It doesn't crash, but it's unusable for the app and would likely get rejected by Apple's review team.
----------
Can you enter this in the bug form?
If can't find it. send email to support and me
c
I am glad camera images are working better in the daily builds, because I was planning to look at this functionality in my next project.
I hope the camera issues gets fixed soon. I need access to the camera and I really want to use this SDK.
I must have missed it, but the camera support for Android dropped from the roadmap. I see from the api page it isn't on Android.
When can the Android platform use the camera?
Thanks
must have been dropped by accident.
go ahead and submit a request ;-) on the road map page.
c.
Hello,
I'm a bit newbie on using the SDK. I am trying to save a picture captured with the camera. When using display.save() I can only save in the 3 predefined folders.
Is there a way of viewing that image in the photoLibrary?
Or what should I use for saving it there?
Thanks.
Any update for camera video? I just want use custom frame and buttons for picture taking.
Is that possible with current builds?
I now have to leave Corona which I'm not happy with, just because I can't use custom layout for camera. Do u have plan for next builds?
Hey
We just got a huge contract and inside that app we need to be able to start the camera in a small window with a little cross on it so that the customer can focus on the accident and then when they press a button we want to grab the image and add some images on top of the live camera image.
This is crucial for the app and we must get this to work inside Corona, I don't want to build this huge project in Titanium Appcelerator which has the support.
So please Carlos & co... maybe some camera addings to the api the upcoming month?
and what about video capture support?
Starting from scratch, I used the sample Camera app here and ran it on my iPhone 4.
This is the result.
http://www.flickr.com/photos/beyondthetech/5416430625/
Here's the Console Log from my iPhone 4:
As you can see, the image capture is registering at a paltry 382x512 from the iPhone 4's 5.0 megapixel camera. Something's clearly wrong here...