Fill MovieClip with webcam output in Haxe
I'm trying to build a simple Flash SWF with Haxe that shows the output of my webcam. I want the SWF to be embeddable and the size to be determined in the HTML. So my HTML looks like:
<html>
<head><title>Web cam</title></head>
<body bgcolor="#dddddd">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
id="haxe"
align="middle"
width="640" height="480">
<param name="movie" value="webcam.swf"/>
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="exactfit" />
<param name="bgcolor" value="#ffffff"/>
<embed src="webcam.swf"
width="640" height="480"
bgcolor="#ffffff"
name="haxe"
quality="high"
align="middle"
allowScriptAccess="always开发者_运维问答"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
</object>
</body>
</html>
This should put a webcam.swf of a size of 640x480. To build webcam.swf
I use the following Haxe script:
class Webcam {
static function main() {
var mc : flash.display.MovieClip;
var rawvideo : flash.media.Video;
var cam:flash.media.Camera = flash.media.Camera.getCamera();
cam.setMode(320, 240, 24, false);
cam.setQuality(0, 100);
mc=flash.Lib.current;
var stage = flash.Lib.current.stage;
stage.scaleMode=flash.display.StageScaleMode.EXACT_FIT;
rawvideo = new flash.media.Video(Std.int(stage.width), Std.int(stage.height) );
rawvideo.attachCamera(cam);
if (cam!=null) {
mc.addChild(rawvideo);
} else {
trace("No Camera");
}
}
}
This creates the SWF file that shows the webcam output but with some big white bands on the right and bottom. I want the webcam image to fill the entire Flash object. What am I doing wrong?
I have had no success getting your code to work at 640x480.
To get it to work at 320x240 change the line:
stage.scaleMode=flash.display.StageScaleMode.EXACT_FIT;
to
stage.scaleMode=flash.display.StageScaleMode.NO_SCALE;
And change the resolution to 320x240 in the HTML.
精彩评论