我使用以下代码从网络摄像头获取图像。我面临的问题是我需要将“位图”与mcVideo相匹配。我不能只做mcVideo.addChild(位图),因为位图大于mcVideo。如何将位图放入mcVideo进行预览?
谢谢!
var bandwidth:int = 0;
var quality:int = 100;
var cam:Camera;
var video:Video;
var captureVideo:Video;
var bitmapData:BitmapData;
var bitmap:Bitmap;
public function Main() {
mcCapture.addEventListener(MouseEvent.CLICK, mcCapture_Click);
cam = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(640,480,30,false);
// The display object:
video = new Video();
video.attachCamera(cam);
video.width = mcVideo.width;
video.height = mcVideo.height;
mcVideo.addChild(video);
// Bitmap to capture full 640x480
bitmapData = new BitmapData(cam.width, cam.height);
bitmap = new Bitmap(bitmapData);
bitmap.width = cam.width;
bitmap.height = cam.height;
trace("Set bitmap width: " + bitmap.width + " Height: " + bitmap.height);
}
public function mcCapture_Click(e:Event):void {
bitmapData.draw(video);
// Code to display preview
trace("done");
}
答案 0 :(得分:0)
您可以使用addChild()
,然后将MC的scaleX
和scaleY
属性设置为大约0.5或0.2,以缩放位图以适应屏幕。
或者您可以使用自定义函数仅绘制位图的一部分,然后裁剪它。
var g:Graphics = MC.graphics;
g.beginBitmapFill(...)
g.drawRect(...)
g.endFill()