AS3 - 网络摄像头视频尺寸未转移到新的 BitmapData 中 - 默认为 320x240
我正在尝试捕获 1920x1080 网络摄像头捕获并使用捕获创建新的位图。我觉得所有尺寸设置都正确,但最终的 1920x1080 位图仅包含视频捕获的小型 320x240 版本。帮助!
import flash.display.Bitmap;
import flash.display.BitmapData;
var bandwidth:int = 1000; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality.
var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(1920,1080,60,true); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = 0;
video.y = -100;
video.width = 1920;
video.height = 1080;
addChild(video);
var bitmapData:BitmapData = new BitmapData(video.width, video.height);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 0;
bitmap.y = 0;
bitmap.width = 1920;
bitmap.height = 1080;
addChild(bitmap);
bitmap.visible = false;
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
bitmap.visible = true;
}
I am attempting to capture a 1920x1080 webcam capture and create a new bitmap with the capture. I feel like I have all the dimension settings correct but the final 1920x1080 bitmap only contains a small 320x240 version of the video capture. Help!
import flash.display.Bitmap;
import flash.display.BitmapData;
var bandwidth:int = 1000; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality.
var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(1920,1080,60,true); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = 0;
video.y = -100;
video.width = 1920;
video.height = 1080;
addChild(video);
var bitmapData:BitmapData = new BitmapData(video.width, video.height);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 0;
bitmap.y = 0;
bitmap.width = 1920;
bitmap.height = 1080;
addChild(bitmap);
bitmap.visible = false;
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
bitmap.visible = true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一段时间在一个几乎相同的问题上苦苦挣扎。位图图像具有所需的大小,但照片本身仅占据位图图像内空间的三分之一 - 在其周围留下大量空白。
希望有人可以提出更好的解决方案,但这就是我所做的解决方案:
我建议您将比例从 3 更改为 1920/320。
另一个提示:设置相机模式后,尝试追踪相机的高度和宽度。这将告诉您实际捕获了多少像素。例如,在我的项目中,我尝试设置以下设置:(
其中 c = 相机)
输出是“960 720 cam res” - 表明这是我的相机可以处理的最大分辨率,而不是所需的 2048 x 1536
结果图片没有像素化,但它不如相机拍摄的图片好本机软件。不确定这是否是由于我的方法或我用来压缩位图数据的 JPGEnocoder 造成的。
另外(我对此可能是错的)-但它可能值得尝试:
从而使带宽不成为考虑因素,并将重点放在质量上。
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:
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:
(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:
thus making the bandwidth not a consideration, and putting the emphasis on the quality.
尝试降低每秒帧数,而不是
尝试
如果您所做的只是拍摄快照,则不需要 60 fps
您的网络摄像头也有可能不支持 1920x1080。如果更改 FPS 没有帮助,也可以尝试较小的尺寸。
Try lowering your Frames per second, instead of
try
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.