Flex4 调用摄像头拍照
<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="500" height="350" creationComplete="application1_creationCompleteHandler(event)"><fx:Script><![CDATA[import mx.controls.Alert;import mx.events.CloseEvent;import mx.events.FlexEvent;import mx.graphics.codec.PNGEncoder;?private const CAMERA_WIDTH:int=400;private const CAMERA_HEIGHT:int=300;private var _camera:Camera;private var _pngEn:PNGEncoder;private var _bitmapData:BitmapData;private var _fr:FileReference;?protected function application1_creationCompleteHandler(event:FlexEvent):void{_pngEn=new PNGEncoder;_fr=new FileReference;?checkCamera();}?private function checkCamera(event:CloseEvent=null):void{_camera=Camera.getCamera();if(_camera!=null){_camera.setMode(400,300,24);_camera.setQuality(0,100);?cameraDisplay.attachCamera(_camera);cutCameraBtn.enabled=true;}else{Alert.okLabel="重试";Alert.show("找不到摄像头,程序将重新查找","对不起",4,null,checkCamera);}}?private function getDateString():String{var date:Date=new Date;return "拍照"+date.getFullYear()+(date.getMonth()+1)+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds()+date.getMilliseconds();}?protected function cutCameraBtn_clickHandler(event:MouseEvent):void{_bitmapData=new BitmapData(CAMERA_WIDTH,CAMERA_HEIGHT);_bitmapData.draw(cameraDisplay);?var bytes:ByteArray=_pngEn.encode(_bitmapData);_fr.save(bytes,getDateString()+".png");?//releasebytes.length=0;_bitmapData.dispose();}?]]></fx:Script><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --></fx:Declarations>?<mx:VideoDisplay id="cameraDisplay" width="400" height="300" y="10" x="50"/><mx:Button id="cutCameraBtn" label="拍照" click="cutCameraBtn_clickHandler(event)" enabled="false" x="227" y="318"/></s:Application>
?? 图片保存为png格式