去年写的。。。。那时候水平低。。。。。大家将就这看啊。。。。。。。 <?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>
<fx eclarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx eclarations>
<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>
|