• 捕获Camera并保存图片到本地(照相功能) samhy



    Flex博文
    捕获Camera并保存图片到本地(照相功能) -samhy
    作者:admin 日期:2010-07-12
    字体大小: 小 中 大

    捕获Camera并保存图片到本地(照相功能)
    这几天对Camera类进行了一下规整,并利用JPGEncoder类实现了照相的功能,代码如下:

    XML/HTML代码
    import flash.media.Camera;
    import flash.system.Security;
    import flash.events.StatusEvent;
    import flash.text.TextField;
    import flash.events.ActivityEvent;
    import flash.events.MouseEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.net.FileReference;
    import com.adobe.images.JPGEncoder;
    //Security.showSettings(SecurityPanel.PRIVACY);
    //打开安全设置
    var timer:Timer = new Timer(100);
    timer.addEventListener(TimerEvent.TIMER,gettimer);
    var txt:TextField = new TextField();
    addChild(txt);
    btn.visible = false;
    var vid:Video;
    var camera:Camera = Camera.getCamera();
    var bitdata:BitmapData;
    var bitmap:Bitmap;
    if(camera == null){ txt.text = ("没有摄像头");
    btn.visible = false; } else { txt.text = ("PC上面有摄像头");
    Connectting();
    }
    function Connectting(){
    vid = new Video(320,240);
    vid.attachCamera(camera);
    vid.x = 0;
    vid.y = 50;
    addChild(vid);
    camera.addEventListener(StatusEvent.STATUS,getStatus);//查看用户是否允许访问摄像头
    }
    function getStatus(e:StatusEvent):void{
    trace(e.code);
    if(e.code == "Camera.Muted"){
    txt.text = ("用户拒绝访问摄像头");
    btn.visible = false;
    } else{
    txt.text = ("用户允许访问摄像头");
    timer.start();
    camera.addEventListener(ActivityEvent.ACTIVITY,getactivity);//查看摄像头的活动
    camera.setQuality(0,100);
    camera.setMode(320,240,24,true);//保证画质
    btn.visible = true;
    btn.addEventListener(MouseEvent.CLICK,saveImg);
    }
    }
    function gettimer(e:TimerEvent):void{
    SXTSL.text = String(camera.currentFPS);
    WZZP.text = String(camera.keyFrameInterval);
    SPYS.text = String(camera.loopback);
    IMGQ.text = String(camera.quality);
    }
    function getactivity(e:ActivityEvent):void{
    ML.text = String(camera.motionLevel);
    XYL.text = String(camera.activityLevel);
    }
    function saveImg(e:MouseEvent):void{
    bitdata= new BitmapData(320,240,true,0x000000);
    bitdata.draw(vid);
    var jpg:JPGEncoder = new JPGEncoder(100);
    var file:FileReference = new FileReference();
    var byteArray:ByteArray = jpg.encode(bitdata);
    file.save(byteArray,"libufan.jpg");//如果要改文件名,请在修改的文件名后面加.jpg
    }
    来源于:http://www.as3hope.com/read.php?3

  • 相关阅读:
    apicloud 运费计算js+页面
    css让字体细长
    vue 请求完接口后执行方法
    js监听当前页面再次加载
    用apicloud+vue的VueLazyload实现缓存图片懒加载
    git merge和git rebase的区别(转)
    yuan先生博客链接
    django组件之contenttype(一)
    Django的orm中get和filter的不同
    python第三方库requests详解
  • 原文地址:https://www.cnblogs.com/zdcaolei/p/2405306.html
Copyright © 2020-2023  润新知