将网络摄像头捕获的静态图像保存在 Flash 中

发布于 2024-09-09 11:19:01 字数 1065 浏览 2 评论 0原文

我已经编写了足够的代码来预览 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 新手。

谢谢, 里希。

I have written enough code to preview the webcam video in Flash.

Now, I want to capture images at 10 second intervals.

Here's my code:

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

Any help please?

I am a total Flash newbie.

Thanks,
Rishi.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

渔村楼浪 2024-09-16 11:19:01

如果您想将其保存到用户的磁盘上,请记住,您不能自动执行此操作,因为出于安全原因,FileReference 类的 save() 方法只能在特定的用户操作(单击、鼠标按下和我)之后使用。猜测按键)。获得位图数据后,您将需要来自 http://code.google.com/ 的 jpeg 编码器p/as3corelib/ 对您的 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);

在此处查看 FileReference 文档 http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/FileReference.html,以便您了解还可以用它做什么。

If you want to save it to the user's disk keep in mind that you can't do it automatically as, for security reasons, the save() method of the FileReference class can only be used after specific user actions (click, mousedown and I guess key-presses). After you have your bitmapdata you'll need the jpeg encoder from http://code.google.com/p/as3corelib/ to encode your img and save it to the disk. Something like this:

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

Take a look at the FileReference doc here http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/FileReference.html so you see what else you can do with it.

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