第九区-Jquery超级群

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 423|回复: 1

在线拍照存放本地 [复制链接]

Rank: 7Rank: 7Rank: 7

发表于 2011-7-12 15:10:26 |显示全部楼层
本帖最后由 king 于 2011-7-12 15:11 编辑

去年写的。。。。那时候水平低。。。。。大家将就这看啊。。。。。。。

<?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" minWidth="955" minHeight="600" height="280" width="328"
      creationComplete="init()">
  <fx:Script>
  <![CDATA[
   import flash.external.ExternalInterface;
   import flash.net.FileReference;
   
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.utils.StringUtil;
   import mx.graphics.codec.JPEGEncoder;
   
   //创建一个基本的网络连接对象
   private var vi:Video;
   private var cam:Camera;      //定义一个摄像头
   private var photoName:String = "";   //图片的名字
   private var userName:String;
   private static const DEFAULT_CAMERA_WIDTH:Number = 320; //摄像头显示宽度
   private static const DEFAULT_CAMERA_HEIGHT:Number = 240; //摄像头显示高度
   private var m_pictureBitmapData:BitmapData //定义视频截图
   private var file:FileReference;
   [Bindable]
   private var m_pictureData:String;//定义一个图片名称
   
   public function init():void{
    submitButton.enabled=false;
    setupCamera();
   }
   public function setupCamera():void{
    //启动摄像头
    cam = Camera.getCamera();
    if(cam != null){
     cam.addEventListener(StatusEvent.STATUS,onStatusHandler);
     cam.addEventListener(ActivityEvent.ACTIVITY,onActiveHandler);
     cam.setMode(320,240,30);
     cam.setQuality(0,70);  //设置清晰度
     vi = new Video();
     vi.width = 320;
     vi.height = 240;
     vi.attachCamera(cam);
     vdisplay.addChild(vi);
     
    }
   }
   private function onActiveHandler(event:ActivityEvent):void
   {
    if(!cam.muted){   //判断摄像头存不存在
     paiButton.enabled = true;
    }else{
     Alert.show("错误:无法链接到活动摄像头!")
    }
    cam.removeEventListener(StatusEvent.STATUS,onStatusHandler);
   }
   
   private function onStatusHandler(event:StatusEvent):void{
    if(!cam.muted){   //判断摄像头存不存在
     paiButton.enabled = true;
    }else{
     Alert.show("错误:无法链接到活动摄像头!")
    }
    cam.removeEventListener(StatusEvent.STATUS,onStatusHandler);
   }
   private function SnapshotPicture():void
   {
    m_pictureBitmapData = new BitmapData(DEFAULT_CAMERA_WIDTH,DEFAULT_CAMERA_HEIGHT);
    m_pictureBitmapData.draw(vdisplay,new Matrix());
    var m_pictureBitmap:Bitmap = new Bitmap(m_pictureBitmapData);
    //t_img_Picture.addChild(m_pictureBitmap);
    //删除原_localVideo
    vi = new Video();
    vi.width = 320;
    vi.height = 240;
    vdisplay.addChild(m_pictureBitmap);
    paiButton.enabled=false;
    submitButton.enabled=true;
//    t_panel_Picture.visible = true;
//    t_ban_Save.enabled = true;
   }
   private function SavePicture():void
   {
   
    downloadFile(m_pictureBitmapData);
   }
   public function downloadFile(myData:BitmapData):void{
   
    file=new FileReference();
    file.addEventListener(Event.COMPLETE,downloadComplete);
    file.save(new JPEGEncoder(80).encode(myData),"graph.jpg");
   }
   
   private function downloadComplete(event:Event):void{
    //Alert.show("成功保存图片到本地!","提示");
   }
  ]]>
</fx:Script>
<fxeclarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fxeclarations>

<s:VideoDisplay x="0" y="0"  width="324.5" height="240" id="vdisplay"/>
<s:Button id="paiButton" x="75" y="249" label="拍照"  click="SnapshotPicture()" enabled="false"/>
<s:Button id="submitButton" x="209" y="249" label="提交"  click="SavePicture()" enabled="false"/>
</s:Application>







标签: 在线拍照 摄像头 视频截图 网络连接 定义 | 编辑标签






Rank: 7Rank: 7Rank: 7

发表于 2011-7-13 17:05:13 |显示全部楼层
学习. 学习. 学习. 学习. 学习. 学习. 学习.

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|第九区-Jquery超级群    点击这里加入此群 点击这里加入此群

GMT+8, 2012-2-8 09:41 , Processed in 0.705342 second(s), 15 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部