• <?xml version="1.0" encoding="utf-8"?> 
  • <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="414" 
  •      height="211" layout="absolute"> 
  •     <mx:Script> 
  •         <![CDATA[ 
  •             import mx.controls.Alert; 
  •             import mx.core.UIComponent; 
  •             var camera:Camera; 
  •             private function videoDisplay_creationComplete():void { 
  •                 camera = Camera.getCamera(); 
  •                 if (camera) { 
  •                     //指定是否播放来自摄像头的视频流。 
  •                     videoDisplay.attachCamera(camera); 
  •                 } else { 
  •                     Alert.show("You don't seem to have a camera."); 
  •                 } 
  •             } 
  •             private function cut_pic():void{ 
  •   var imgBD:BitmapData=new BitmapData(camera.width,camera.height); 
  •                 imgBD.draw(videoDisplay,new Matrix()); 
  •                 var imgBitmap:Bitmap=new Bitmap(imgBD); 
  •                 //创建一个UIComponent对象  
  •                 var uic:UIComponent = new UIComponent();  
  •                 //将Bitmap对象加入到UIComponent对象中  
  •                 uic.addChild(imgBitmap);  
  •                 showimg.addChild(uic); 
  •             } 
  •         ]]> 
  •     </mx:Script> 
  • <!--使用 VideoDisplay 控件,您可以在 Flex 应用程序中播放 FLV 文件。 
  • 它支持通过 HTTP 进行渐进式下载,从 Flash Media Server 和 Camera  
  • 对象进行流式传输。--> 
  •     <mx:VideoDisplay id="videoDisplay" width="160" height="120"  
  •         x="27" y="10" creationComplete="videoDisplay_creationComplete();"/> 
  •     <mx:Button x="27" y="154" label="照相" width="160" height="35"  
  •         click="cut_pic()" fontSize="12"/> 
  •     <mx:Canvas x="218" y="11" width="166" height="119" id="showimg"> 
  •     </mx:Canvas> 

    简要说明:使用 VideoDisplay 控件,您可以在 Flex 应用程序中播放 FLV 文件。它支持通过 HTTP 进行渐进式下载,从 Flash Media Server 和 Camera 对象进行流式传输。第13行videoDisplay.attachCamera(camera);指定是否播放来自摄像头的视频流。

posted on 2012-10-30 13:02  sagittar  阅读(421)  评论(0)    收藏  举报