打算在网页里用swf显示摄像头,但是这个摄像头的video无法控制大小
<?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"
creationComplete="showCamera(event)">
<fx:Script>
<![CDATA[
import flash.net.FileReference;
import flash.net.URLRequest;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.graphics.ImageSnapshot;
import mx.graphics.codec.PNGEncoder;
import mx.rpc.http.HTTPService;
private var camera:Camera;
private var video:Video;
protected function showCamera(event:FlexEvent):void{
camera=Camera.getCamera();
if(camera!=null){
video=new Video(200,150);
video.attachCamera(camera);
video.x=0;
video.y=0;
myUI.addChild(video);
}else{
Alert.show("对不起,您没有摄像头!");
}
}
public function takePic(event:MouseEvent):void{
Alert.show("clicked");
var jpgSource:BitmapData= new BitmapData(video.width,video.height);
var myMatrix:Matrix=new Matrix();
jpgSource.draw(video,myMatrix);
var png:PNGEncoder = new PNGEncoder();
var imgbyte:ByteArray=png.encode(jpgSource);
var request:URLRequest = new URLRequest("http://127.0.0.1:8080/takePic/servlet/getPic");
var loader:Loader = new Loader();
request.data = imgbyte;
request.method = flash.net.URLRequestMethod.POST;
request.contentType = "application/octet-stream";
loader.load( request );
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<mx:UIComponent width="200" height="150" id="myUI" />
<s:Button x="100" y="150" label="拍照" id="imgBtn" click="takePic(event)"/>
</s:Application>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>${title}</title>
<meta name="google" value="notranslate" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "${version_major}.${version_minor}.${version_revision}";