从文档:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraUI.html#includeExamplesSummary
编辑
[我的移动应用程序的相机代码]
package com.shaunhusain.fingerPainting.tools
{
import flash.display.Loader;
import flash.display.Stage;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MediaEvent;
import flash.events.TouchEvent;
import flash.media.CameraUI;
import flash.media.MediaPromise;
import flash.media.MediaType;
public class CameraTool extends ToolBase implements ITool
{
//--------------------------------------------------------------------------------
// Variables
//--------------------------------------------------------------------------------
private var deviceCameraApp:CameraUI = new CameraUI();
private var imageLoader:Loader;
//--------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------
public function CameraTool(stage:Stage) {
super(stage);
if( CameraUI.isSupported )
{
trace( "Initializing camera..." );
deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
}
else
{
trace( "Camera interface is not supported.");
}
}
//--------------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------------
public function takeAction(event:TouchEvent=null):void
{
model.disableNextAutosave = true;
deviceCameraApp.launch( MediaType.IMAGE );
}
//--------------------------------------------------------------------------------
// Camera UI functions
//--------------------------------------------------------------------------------
private function imageCaptured( event:MediaEvent ):void
{
trace( "Media captured..." );
var imagePromise:MediaPromise = event.data;
if( imagePromise.isAsync )
{
trace( "Asynchronous media promise." );
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );
imageLoader.loadFilePromise( imagePromise );
}
else
{
trace( "Synchronous media promise." );
imageLoader.loadFilePromise( imagePromise );
showMedia( imageLoader );
}
}
private function captureCanceled( event:Event ):void
{
trace( "Media capture canceled." );
}
private function asyncImageLoaded( event:Event ):void
{
trace( "Media loaded in memory." );
showMedia( imageLoader );
}
private function showMedia( loader:Loader ):void
{
loader.scaleX=-1;
layerM.addLayer( loader );
}
private function cameraError( error:ErrorEvent ):void
{
trace( "Error:" + error.text );
}
public function toString():String
{
return "Loading CameraUI";
}
}
}
这是我项目中的一个示例:
https ://github.com/wafflejock/FingerPainting/blob/master/FlashBuilderProject/FingerPainting/src/com/shaunhusain/fingerPainting/tools/CameraTool.as
演示/无耻自我宣传:
https://play.google.com/store/apps/details?id=air.com.chitowngames.DigitalDoodler
您可以更改有关加载程序的 showMedia 函数中发生的情况。因此,如果您想访问 BitmapData,只需执行以下操作:
(loader.content as Bitmap).bitmapData