加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex4实现Camera拍照功能!!

发布时间:2020-12-15 05:01:56 所属栏目:百科 来源:网络整理
导读:?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" heig
<?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"); ?? ??? ??? ??? ? ?? ??? ??? ??? ?//release ?? ??? ??? ??? ?bytes.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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读