AS3 - 网络摄像头视频尺寸不会延续到新的 BitmapData - 默认为 320x240 [英] AS3 - Webcam video dimensions not carrying over into new BitmapData - defaulting to 320x240

查看:19
本文介绍了AS3 - 网络摄像头视频尺寸不会延续到新的 BitmapData - 默认为 320x240的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试捕获 1920x1080 网络摄像头捕获并使用捕获创建一个新位图.我觉得我的所有尺寸设置都正确,但最终的 1920x1080 位图仅包含视频捕获的 320x240 小版本.帮助!

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;
}

推荐答案

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

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 );

对于您的示例,我建议将比例从 3 更改为 1920/320.

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");

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

(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

生成的图片没有像素化,但不如原生软件捕获的图片那么好.不确定这是因为我的方法还是我用来压缩位图数据的 JPGEnocoder.

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.

这篇关于AS3 - 网络摄像头视频尺寸不会延续到新的 BitmapData - 默认为 320x240的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆