From 4102fd95eea205387bfc8cdc3afe5bafc0f89aec Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 15 Apr 2008 05:08:10 +0000 Subject: [PATCH] Q: why isn't whirled done yet? A: shit like this. 30 minutes of tweaking and trying things to get it to ACTUALLY snapshot at specified size. The damn video control always says that videoWidth and videoHeight are 0, but if you size the Camera correctly and attach the video it works. Turns out that the video control, when snapshotted into a bitmapdata, always thinks it's 160x120, but if we scale it up we can see the pixel data that's really there. What the fuck?! Oh well, it works now, but why does adobe make these things so difficult? The only reason I got it working was trial and error and cargo-culting off the example in Camera's API docs. Jeez. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@465 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/flash/CameraSnapshotter.as | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/flash/CameraSnapshotter.as b/src/as/com/threerings/flash/CameraSnapshotter.as index 19848498..d64037b0 100644 --- a/src/as/com/threerings/flash/CameraSnapshotter.as +++ b/src/as/com/threerings/flash/CameraSnapshotter.as @@ -7,6 +7,8 @@ import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; +import flash.geom.Matrix; + import flash.media.Camera; import flash.media.Video; @@ -79,10 +81,7 @@ public class CameraSnapshotter extends Sprite return; } - _video = new Video(_camera.width, _camera.height); - _bitmap = new Bitmap(new BitmapData(_camera.width, _camera.height, false)); - _video.attachCamera(_camera); - addChild(_video); + attachVideo(); } public function getCameraName () :String @@ -96,9 +95,10 @@ public class CameraSnapshotter extends Sprite */ public function setMode (width :int, height :int, fps :Number, favorArea :Boolean = true) :void { + clearSnapshot(); + removeChild(_video); _camera.setMode(width, height, fps, favorArea); - _video.width = _camera.width; - _video.height = _camera.height; + attachVideo(); } public function takeSnapshot () :void @@ -107,7 +107,11 @@ public class CameraSnapshotter extends Sprite return; // throw exception? } - _bitmap.bitmapData.draw(_video); + // for some reason the video seems to always be locked at 160x120 when we try to + // draw it, so we do some scaling... + var matrix :Matrix = new Matrix(_camera.width / 160, 0, 0, _camera.height / 120); + _bitmap.bitmapData.draw(_video, matrix); + if (_video.parent != null) { removeChild(_video); addChild(_bitmap); @@ -133,6 +137,17 @@ public class CameraSnapshotter extends Sprite return _bitmap.bitmapData; } + protected function attachVideo () :void + { + _video = new Video(_camera.width, _camera.height); + // the constructor args don't seem to do dick, so we set the values again... + _video.width = _camera.width; + _video.height = _camera.height; + _video.attachCamera(_camera); + addChild(_video); + _bitmap = new Bitmap(new BitmapData(_camera.width, _camera.height, false)); + } + protected var _camera :Camera; protected var _video :Video;