繁体   English   中英

从Flash中保存摄像头捕获的静止图像

[英]Save captured still image from webcam in Flash

我已经编写了足够的代码来预览Flash中的网络摄像头视频。

现在,我想以10秒的间隔捕获图像。

这是我的代码:

import flash.display.BitmapData
import flash.geom.Matrix
import com.adobe.images.JPGEncoder;
import flash.net.FileReference;

//get the default camera
//change your Default camera using the Flash Player Settings.
cam=Camera.get()
//this event is called whenever permission to access the local camera, is accepted or denied by the user
cam.onStatus=function(e)
{
    //if we are given permission
    if(e.code == "Camera.Unmuted")
    {
        //start the application
        initialize()
    }
    else
    {
        System.showSettings(3)
    }
}

var snapshot:BitmapData=new BitmapData(cam._width,cam._height);

function takeSnapshot()
{
    snapshot.draw(cam,new Matrix());
}


//if there are no Cameras
if(cam == null)
{
    System.showSettings(3)
}
else
{
    cam.setMode(1024, 768, 30);
    cam.setQuality(10000,0);
    output.attachVideo(cam);
    setInterval(this,"takeSnapshot",1000);
}

有什么帮助吗?

我是Flash的新手。

谢谢Rishi

如果要将其保存到用户磁盘,请记住您不能自动执行此操作,出于安全原因,FileReference类的save()方法只能在特定的用户操作(单击,鼠标按下和猜测按键)。 获得位图数据后,您将需要http://code.google.com/p/as3corelib/中的jpeg编码器来对img进行编码并将其保存到磁盘。 像这样:

    var fileBrowser:FileReference = new FileReference();

    var bd:BitmapData = new BitmapData(imageContainer.width, imageContainer.height, false, 0xFFFFFF);

    bd.draw(imageContainer);

    var encoder:JPGEncoder = new JPGEncoder(35);

    var bytes:ByteArray = encoder.encode(bd);

    fileBrowser.save(bytes);

http://help.adobe.com/zh_CN/AS3LCR/Flash_10.0/flash/net/FileReference.html上查看FileReference文档,这样您就可以使用它了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM