-
-
Save marchbold/9798165 to your computer and use it in GitHub Desktop.
/** | |
* __ __ __ | |
* ____/ /_ ____/ /______ _ ___ / /_ | |
* / __ / / ___/ __/ ___/ / __ `/ __/ | |
* / /_/ / (__ ) / / / / / /_/ / / | |
* \__,_/_/____/_/ /_/ /_/\__, /_/ | |
* / / | |
* \/ | |
* http://distriqt.com | |
* ------------------------------------- | |
* | |
* brief: Camera ANE example for timeline usage | |
* tag: distriqt.extension.camera | |
* | |
*/ | |
import com.distriqt.extension.camera.Camera; | |
import com.distriqt.extension.camera.CameraMode; | |
import com.distriqt.extension.camera.CameraParameters; | |
import com.distriqt.extension.camera.CaptureDevice; | |
import com.distriqt.extension.camera.events.CameraDataEvent; | |
import com.distriqt.extension.camera.events.CameraEvent; | |
var lastFrameProcessed:Number = -1; | |
var videoData:ByteArray = new ByteArray(); | |
var bitmapData:BitmapData = new BitmapData( 640, 480, false ); | |
// This bitmap will hold the view from the camera | |
var bitmap:Bitmap = new Bitmap( bitmapData ); | |
addChild( bitmap ); | |
var dev_key:String = ""; | |
// | |
// You'll need to create some interface to take the photo - for demonstration purposes we'll just add a click listener | |
stage.addEventListener( MouseEvent.CLICK, clickHandler, false, 0, true ); | |
try | |
{ | |
com.distriqt.extension.camera.Camera.init( dev_key ); | |
if (com.distriqt.extension.camera.Camera.isSupported) | |
{ | |
var options:CameraParameters = new CameraParameters(); | |
options.enableFrameBuffer = true; | |
options.frameBufferWidth = 800; | |
options.frameBufferHeight = 600; | |
options.cameraMode = new CameraMode( CameraMode.PRESET_MEDIUM ); | |
com.distriqt.extension.camera.Camera.instance.addEventListener( CameraEvent.VIDEO_FRAME, camera_videoFrameHandler, false, 0, true ); | |
com.distriqt.extension.camera.Camera.instance.addEventListener( CameraDataEvent.CAPTURED_IMAGE, camera_capturedImageHandler, false, 0, true ); | |
com.distriqt.extension.camera.Camera.instance.initialise( options ); | |
} | |
} | |
catch (e:Error) | |
{ | |
} | |
function camera_videoFrameHandler( event:CameraEvent ):void | |
{ | |
var frame:Number = com.distriqt.extension.camera.Camera.instance.receivedFrames; | |
if (frame != lastFrameProcessed) | |
{ | |
com.distriqt.extension.camera.Camera.instance.getFrameBuffer( videoData ); | |
var rect:Rectangle = new Rectangle( 0, 0, com.distriqt.extension.camera.Camera.instance.width, com.distriqt.extension.camera.Camera.instance.height ); | |
if (bitmapData.width != com.distriqt.extension.camera.Camera.instance.width || bitmapData.height != com.distriqt.extension.camera.Camera.instance.height) | |
{ | |
bitmapData = new BitmapData( com.distriqt.extension.camera.Camera.instance.width, com.distriqt.extension.camera.Camera.instance.height, false ); | |
bitmap.bitmapData.dispose(); | |
bitmap.bitmapData = bitmapData; | |
} | |
try | |
{ | |
bitmapData.setPixels( rect, videoData ); | |
} | |
catch (e:Error) | |
{ | |
trace( "ERROR::setPixels: " + e.message ); | |
} | |
videoData.clear(); | |
lastFrameProcessed = frame; | |
} | |
} | |
function clickHandler( event:MouseEvent ):void | |
{ | |
// Start the image capture | |
com.distriqt.extension.camera.Camera.instance.captureImage( false ); | |
} | |
function camera_capturedImageHandler( event:CameraDataEvent ):void | |
{ | |
// Here the event.data property will hold the BitmapData from the image capture. | |
// You can add this to your interface as you see fit | |
} | |
// com.distriqt.Camera |
Just for others who come across this, have a look at this example for starling: https://gist.github.com/marchbold/0075bbf8ccf46ac76668
I use this example to take photos on iPhone 6 and save them in camera roll. No problem so far. But how to start video recording and how to save video on iPhone's camera roll? And how to switch front / back camera? Can you please give (timeline) examples for those not so used in AS3? Thanks in advance.
I have created another .fla file & i am calling timeline.as
// 1st line in my .fla
import timeline;
The target is Air 19.0.0.147 for iOS
as per the above example clicking anywhere on the stage should take a picture & display on stage, but when i publish this .ipa to my iPad & i click on the screen, nothing happens. Kindly help.
in timeline.as i have added the dev_key that was generated for my app
var dev_key:String = "xxxxxxxxxxxxxx";
Hi,
We don't get notifications on comments on gists. Please post your questions in the support forum: https://github.com/distriqt/ANE-Camera/issues
Cheers
Is there any way to use this on Starling? I couldn't add the resulting bitmap to starling app.