1
votes

I have a kiosk that takes peoples images using flash webcam video. We are using a 16:9 camera, but we need the images it takes to be 4:3. So I just made the stage 4:3 and added the video to it, and that solves it on the kiosk UI.

But... I am sending these images over to javascript via a base64 encoded jpg using ExternalInterface, and that works great. However, when I grab a video frame to send over, it is still the 16:9 of course.

So I need to crop the video so that when I grab it (or a display object it is added to), it is just the 4:3 image.

I tried using a mask, but it wouldn't take for some reason.

video = new Video(videoHeight, videoWidth); //backwards on purpose
video.x = -(videoWidth - stage.stageWidth) /2; //Center X
video.y = -(videoHeight - stage.stageHeight) /2; //Center Y


var maskSprite:Sprite = new Sprite();
maskSprite.graphics.drawRect(0,0,640,480);

video.mask(maskSprite);

Any ideas?

1
Why not to use Camera.setMode()? - Art
How are you grabbing the video frame? Can you post that code? - redhotvengeance
@Art setMode is not set to the same aspect ratio seems to squish the video. - Adam Meyer
@ilollar var bmd:BitmapData = new BitmapData(video.width, video.height); bmd.draw(video); imagePreview = new Bitmap(bmd); this.addChild(imagePreview); - Adam Meyer

1 Answers

0
votes

Masking video won't make a difference, since the draw method of BitmapData is drawing from video itself (which won't include masking) If you put video and the mask into another Sprite and used draw on that Sprite, then the mask would work.

The best solution, however, is probably to adjust the rectangle of what the BitmapData is drawing. You'll also probably want to adjust the width and height of the BitmapData as well:

var bmd:BitmapData = new BitmapData(640, 480);
bmd.draw(video, null, null, null, new Rectangle(0, 0, 640, 480));

Basically, you're defining a rectangle for the clipRect parameter, and setting the size of that rectangle to the final size (and aspect ratio) of what you're trying to capture.