AIR应用 调用摄像头拍照并把照片保持到本地文件夹

import com.adobe.images.PNGEncoder;
import com.adobe.images.JPGEncoder;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import flash.media.Camera;
import flash.media.Video;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.utils.ByteArray;

Security.showSettings(SecurityPanel.CAMERA);  //显示摄像头选择面板
var cam:Camera = Camera.getCamera();
cam.setMode(738, 499, 24);                //摄像头视窗大小
var video:Video = new Video(738,499);
video.attachCamera(cam);
this.addChild(video);
video.x = 276;
video.y = 104;

this.addChild(btn);

//全屏
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
btn.addEventListener(MouseEvent.MOUSE_DOWN, saveStill);

var count:int = 0;

function saveStill(e:MouseEvent):void{
	if(count >49)count = 0;
	var mtr:Matrix = new Matrix(476/738,0,0,370/499,0,0);  //把相框的图片按比例缩小
	var bmd:BitmapData = new BitmapData(476, 370);  //最终保存成的图片大小 
	bmd.draw(video,mtr);
	
	//保存成jpg图片
	var jpg:JPGEncoder = new JPGEncoder();
	var ba:ByteArray=jpg.encode(bmd);
	
	/*  保存成png图片
	var ba:ByteArray = PNGEncoder.encode(bmd);
	var file:File = File.desktopDirectory.resolvePath("webcam" + count++ + ".png");
	var file:File = File.documentsDirectory.resolvePath("G:\PHPnow\htdocs\phpgetpic\upload\webcam" + count++ + ".png");
	*/
	var file:File = File.applicationStorageDirectory.resolvePath("G:\\PHPnow\\htdocs\\phpgetpic\\upload\\webcam" + count++ + ".jpg");
	var fileStream:FileStream = new FileStream();
	fileStream.open(file, FileMode.WRITE);
	fileStream.writeBytes(ba);
	fileStream.close();
	
	//socket 广播出去
	//sendStr("webcam" + (count-1));
}
跟本站发布的“php获取本地图片文件并生成xml文件输出”结合加socket可实现一台电脑拍照,另一台电脑显示拍得的照片。

你可能感兴趣的:(AIR)