How can I capture an image from the webcam and have it be a specific size, without whitespace?
I specify the desired size:
var screenshot:BitmapData = new BitmapData(VD1.width,VD1.height,false);
That's 400x300
And then I draw to the bitmap from my Video element
screenshot.draw(VD1);
I can do Camera.getCamera.height
and .width
and see that my camera is 352x264px
When I view the resulting image, I see whitespace all around the edges (colored grey, so you can tell), like this:![enter image description here][1]
If you measure the actual image, you'll see that it doesn't even take up 352x264 pixels. Even with that measurement, there still exists whitespace around the right and bottom edges.
The Camera.setMode
method upscales the capture to fit 400x300, but it seems like taking a direct capture from the Video object that it's attached to (with VD1.attachCamera(myCam)
outputs a different result when the VD1 object is drawn to a bitmap.
I'd like all my captured images to be the same size, regardless of camera resolution. Is there a way I Can do this?
For reference, here's how I capture the image:
private function takeScreenShot():void{
var screenshot:BitmapData = new BitmapData(VD1.width,VD1.height,false);
screenshot.draw(VD1);
var encoder:PNGEncoder = new PNGEncoder();
var pngByteArray:ByteArray = encoder.encode(screenshot);
var responder:Responder = new Responder(function(res:Object):void{
trace("createThumbnail success");
},
function(res:Object):void{
trace("createThumbnail call failed");
});
mync.call("saveThumbnail", responder,pngByteArray);
}
Here's how I set up my camera
VD1 = new Video();
VD1.width = 400;
VD1.height = 300;
myMic = Microphone.getMicrophone();
myMic.rate = 22;
myMic.setSilenceLevel(0);
myMic.setUseEchoSuppression(true);
myMic.soundTransform = new SoundTransform(0,0);
myCam = Camera.getCamera();
trace(myCam.height+","+ myCam.width);
myCam.setMode(400,300,15);
myCam.setQuality(0,100);
myCam.setLoopback(true);
You probably cannot change the dimensions that the image is captured at, but you can resize the image. Here is a link to another StackOverflow question with info on resizing.