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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user