我有一个我从朋友那里得到的灵活代码。但我想自定义此代码以解决我的需求。我想在jsp上加载一个宽度和高度到flex代码,当它可能在applet上加载时。此宽度和高度将决定捕获图像的宽度和高度。捕获图像后,单击“完成”按钮,调用服务器URL传递捕获图像的java字节[]。以下是代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="videoDisplay_creationComplete();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" x="149" y="131">
<mx:Script>
<![CDATA[
import mx.graphics.ImageSnapshot;
import mx.controls.Alert;
public var cam:Camera = Camera.getCamera();
public var video:Video = new Video(320,240);
public var bitmapData:BitmapData = new BitmapData(video.width,video.height);
public var snapshot:BitmapData;
public function init():void
{
videoDisplay.visible=false;
}
public function start():void{
if (cam == null)
{
Alert.show("No camera is installed","Unable to start capture!!!!");
return;
}
video.attachCamera(cam);
video.x = 20;
video.y = 20;
addChild(video);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 360;
bitmap.y = 20;
addChild(bitmap);
}
private function captureImage(e:MouseEvent):void
{
bitmapData.draw(video);
}
private function videoDisplay_creationComplete():void
{
btnRestartCapture.enabled=false;
if (cam!=null) {
videoDisplay.attachCamera(cam);
} else {
Alert.show("You don't seem to have a camera.");
}
}
public function takeSnapshot():void
{
snapshot = ImageSnapshot.captureBitmapData(videoDisplay);
var bitmap:Bitmap= new Bitmap(snapshot);
img.source=bitmap;
videoDisplay.visible=false;
btnRestartCapture.enabled=true;
}
public function sendToServer():void{
var loader:URLLoader= new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.data=snapshot.getPixels(new Rectangle(0,0,img.width,img.height));
}
private function callJavaScript():void {
ExternalInterface.call("recievePictureFromFlex",snapshot.getPixels(new Rectangle(0,0,img.width,img.height)));
}
public function restartCap():void{
videoDisplay.visible=true;
btnRestartCapture.enabled=false;
}
public function done():void
{
Alert.show("Done taking pix", "Done");
}
]]>
</mx:Script>
<!--<mx:Button label="Capture Image" click="captureImage(null);" id="capture_mc"/>-->
<mx:VBox x="405" y="115" backgroundColor="white" >
<mx:Canvas width="100%" height="100%">
<mx:Image width="350" id="img" height="300"/>
<mx:VideoDisplay id="videoDisplay"
creationComplete="videoDisplay_creationComplete();"
width="350"
height="300" x="0" y="0"/>
</mx:Canvas>
<mx:HBox>
<mx:Button id="btnRestartCapture" label="Clear Picture" click="restartCap();"/>
<mx:Button id="snapButton" label="Snap" click="takeSnapshot()" width="113"/>
<mx:Button id="doneButton" label="Done" click="done()" width="113"/>
</mx:HBox>
</mx:VBox>
</mx:Application>
答案 0 :(得分:0)
对于jsp - &gt; Flex通信,你可以使用flashvars: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html