AS3 - 网络摄像头视频尺寸未转移到新的 BitmapData 中 - 默认为 320x240

发布于 2024-12-29 19:06:29 字数 1122 浏览 2 评论 0原文

我正在尝试捕获 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2025-01-05 19:06:29

我有一段时间在一个几乎相同的问题上苦苦挣扎。位图图像具有所需的大小,但照片本身仅占据位图图像内空间的三分之一 - 在其周围留下大量空白。

希望有人可以提出更好的解决方案,但这就是我所做的解决方案:

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

我建议您将比例从 3 更改为 1920/320。

另一个提示:设置相机模式后,尝试追踪相机的高度和宽度。这将告诉您实际捕获了多少像素。例如,在我的项目中,我尝试设置以下设置:(

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

其中 c = 相机)
输出是“960 720 cam res” - 表明这是我的相机可以处理的最大分辨率,而不是所需的 2048 x 1536

结果图片没有像素化,但它不如相机拍摄的图片好本机软件。不确定这是否是由于我的方法或我用来压缩位图数据的 JPGEnocoder 造成的。

另外(我对此可能是错的)-但它可能值得尝试:

c.setQuality(0,100);

从而使带宽不成为考虑因素,并将重点放在质量上。

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.

月亮坠入山谷 2025-01-05 19:06:29

尝试降低每秒帧数,而不是

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

尝试

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

如果您所做的只是拍摄快照,则不需要 60 fps

您的网络摄像头也有可能不支持 1920x1080。如果更改 FPS 没有帮助,也可以尝试较小的尺寸。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文