Why camera native extension for iOS?
Adobe AIR has its limitations, when it comes to control over an iPhone or iPad camera functions, such as focus, exposure and white balance. This Camera Native Extension offers an API for accessing these functions and adds options for applying filters for cropping and rotating frames. Dig in.
Where’s the code?
April 2014 update: We have turned this project into a step-by-step tutorial with complete source code. Check it out on our new website, EasyNativeExtensions.com.
What does it do?
The Extension allows you to capture static frames from the iPhone/iPad video camera at a frame rate and resolution, chosen by you.
You have the option to lock the focus, exposure or white balance or to have them done automatically by the camera. You can also set a point of interest to expose for or to focus on.
The extension also allows you to rotate, crop or translate frames, as they come in.
Here is a brief video demonstration:
Are there examples with code?
Of course, there is a Wiki page full of them: Examples on how to use the Native Camera Extension.
How do you build the extension?
The extension code comes with ANT and bash scripts, which automate the building process. For more information see our previous blog post One-step build: AIR mobile project with an iOS native extension.
ActionScript 3 API for the extension
The extension exposes the following API at the moment. Click on a function name to see a detailed explanation or go to the Native Camera Extension API Wiki page:
- startVideoCamera
- stopVideoCamera
- getFrameBuffer
- setExposureMode
- setFocusMode
- setWhiteBalanceMode
- setRotationAngle
- setTranslationPoint
- setCropRectanglePixels
Want more?
This extension hooks into the video stream and extracts frames as they come in. It can be extended with functionality to take static photos or to save video files, if there is interest.
What would you like to see it do next?
Leave a comment below or get in touch via support@diadraw.com.
Want more functionality and Android support?
Check out our DiaDraw Native Camera Driver.
It comes with a special offer until December 31st 2014: get any edition of the DiaDraw Native Camera Driver and receive a free copy of our Easy Native Extensions book, Padawan Package.
Please add a download to the project! This is really awesome!
Hi David,
I’ve now added a download: http://code.google.com/p/diadraw-air-camera-native-extension/downloads/list
Check it out and let us know what you think.
Thanks,
Radoslava
An android version would be cool 😛
Thank you very much, this project helps me a lot.
I’m building my own ane to show the camera. It works ok and I’m able to show the preview camera ok.
However, I have a problem. I want to show an image above the camera preview (like a barcode scanner) and I’ve been unable to see the image, I only see the preview camera.
Do you know how I should do this?
Thank you very much.
Hi Almudena,
Thanks for using our extension!
Is the image you want to show above the preview separate or do you want to combine it with the camera preview frames for a single composite image?
If it’s separate, all you should have to do is add its tag after the where you display the video preview.
For image compositing this might help you, if you want to do it on the ActionScript side:
http://stackoverflow.com/questions/9651513/actionscript-3-load-combine-and-save-external-images
Hope that helps,
Radoslava
Hi, thanks a lot for the extension. Exactly what I need. But I got a little problem: the camera image looks like the colors are inverted. Can you imagine what the problem is? I use it for iPhone 4S. Thanks!
Hi Stefan,
The ByteArray that arrives from the ANE has LITTLE_ENDIAN byte ordering and the Flex image component that displays it (if this is what you use) reads it as BIG_ENDIAN by default, that’s probably the cause of the color inversion you are seeing.
In your app, when you receive the ByteArray, set its endian property to Endian.LITTLE_ENDIAN – this should be all you need to do.
I.e. _bufferData.endian = Endian.LITTLE_ENDIAN;
Hope that solves the problem, let me know if it doesn’t.
Thanks for using our extension!
Radoslava
Hi Radoslave
Thanks for building this amazing ANE !
I’m just wondering is this possible to record video and save it directly without bump out the native Camera UI with your ANE ?
Thanks so much
Hi YHS,
Thanks for stopping by!
You can use the ANE and add code to record video without the need for UI, yes.
What you need is an AVAssetWriter, which you will ask to record each frame as it comes in captureOutput() (have a look at CameraDelegate.m)
You can configure it to record sound too: you’ll need to add an audio input and output (similar to addVideoInput() and addVideoOutput() in CameraDelegate.m). When that’s configured, audio samples, as well as video frames will start arriving in captureOutput().
When you have finished recording, you can use the AVAssetWriter to save the video to a file.
Hope this helps, let us know how you get on!
Radoslava
hello Radoslave
I’ve try your ANE these days and use some basic function you build. It took me some times because I only can understand AS3 but not MXML. So I just trying to modify into whole AS3.
now I’m running the function “displayFrame” and get some data,then passing into a bitmap instead of a image(you define in MXML).
But After I Stop Camera,It seems not save into the cameraRoll?
Is this because I need AVAssetWriter to save it ?
And maybe I have to modify at CameraDelegate.m, though in this moment Xcode is totally beyond me.
Thanks for your reply
Hi, so, can this N.E. take single shots? Or is it limited to dealing only with video?
Thanks so much, and for sharing!
Hi asking,
The ANE captures video preview frames and supplies them to AIR. It doesn’t do single shots, but can be extended to do it – an idea for a potential update.
Greetings,
Radoslava
Hi,
This ane is exactly what Im looking for but cant get it to work. I must be doing something really dumb
I get an error saying “TypeError: Error #1009: Cannot access a property or method of a null object reference”
It seems to fall over at the line:
if ( m_cameraExt.startVideoCamera( RESOLUTION_PRESET, MIN_FRAMES_PER_SECOND, MAX_FRAMES_PER_SECOND, m_usingFrontCamera ) )
Any help would be great! Im using Flash Builder 4.7 and just AS3 (no MXML)
Thanks for your great work!
Hi CHL,
Thank you for downloading our extension!
It looks like m_cameraExt might be null at the time when you call m_cameraExt.startVideoCamera().
Does m_cameraExt = new NativeCameraExtension() get called before that?
Greetings,
Radoslava