AS3 - Webcam video dimensions not carrying over into new BitmapData - defaulting to 320x240

为君一笑 提交于 2019-12-01 01:57:56

I struggled with an almost identical issue for a while. The bitmap image was the desired size, but the photo itself only took up a third of the space within the bitmap image - leaving lots of white space around it.

Hopefully someone can suggest a better solution, but here's what I did to work around it:

var trans:Matrix = new Matrix();
trans.scale(3, 3); 
bitmapData.draw(v, trans );

I would suggest for your example, change the scale from 3 to 1920/320.

Another tip: after setting the camera mode, try tracing the camera height and width. This will tell you how many pixels are actually being captured. For example, in my project I tried setting the following settings:

c.setMode(2048, 1536, 5, true);
trace (c.width, c.height, "cam res");

(where c = the camera) The output was "960 720 cam res" - suggesting that this was the maximum resolution my camera could handle, rather than the desired 2048 by 1536

The resultant picture wasn't pixelated, but it wasn't quite as good as pictures captured by the native software. Not sure if this was because of my method or the JPGEnocoder I used to compress the bitmap data.

Also (and I might be wrong about this) - but it might be worth trying:

c.setQuality(0,100);

thus making the bandwidth not a consideration, and putting the emphasis on the quality.

Try lowering your Frames per second, instead of

cam.setMode(1920,1080,60,true); //60 FPS

try

cam.setMode(1920,1080,10,true); //10 FPS

You don't need 60 fps if all you are doing is taking a snapshot

There is also the possibility that your webcam might not support 1920x1080. Maybe try smaller sizes as well if changing FPS doesn't help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!