flash - 使用闪光灯捕获网络摄像头图像?

标签 flash servlets red5

是否有任何开源 Flash 实用程序可以嵌入到网页中并使用它来捕获用户网络摄像头图像或短片,然后“POST”到我的服务器 servlet?我不寻找流媒体视频,所以我不需要 red5 或 flash 服务器。你们能详细说明一下吗...?

最佳答案

这听起来很适合 Thibault Imbert's AS3 GIF Animation Encoding Class .
大约 2 年前,我在大学的一个项目中使用了它。你可以看看here .
在我看来,您将有 3 个步骤:

//1.Create a Camera object

//this code comes from the LiveDocs
var camera:Camera = Camera.getCamera();
var video:Video;            
if (camera != null) {
    video = new Video(camera.width * 2, camera.height * 2);
    video.attachCamera(camera);
    addChild(video);
} else {
    trace("You need a camera.");
}

//2. Take one or more 'screenshots' using BitmapData

    var screenshot:BitmapData = new BitmapData(video.width,video.height,false,0x009900);
    screenshot.draw(video);
    //you would probably save more of these in an array called screenshots maybe

//3. Create a GIFEncoder and send it to the server:



//assuming screenshots is an array of BitmapData objects previously saved
var animationEncoder:GIFEncoder = new GIFEncoder();
animationEncoder.setRepeat(0);
animationEncoder.setDelay (150);
animationEncoder.start();
for(var i:int = 1 ; i < screenshots.length ; i++){
    animationEncoder.addFrame(screenshots[i]);
}
animationEncoder.finish();
//save it on the server
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");//binary header
var gifRequest:URLRequest = new URLRequest ('http://yourServer/writeGIF.php?name=myFile.gif&method=download');
gifRequest.requestHeaders.push (header);
gifRequest.method = URLRequestMethod.POST;
gifRequest.data = animationEncoder.stream;
sendToURL(gifRequest);



//Obviously you would have listeners to check if everything was ok, and when the operation //is complete.

//The PHP code would be something simple as this

    <?php

    $method = $_GET['method'];
    $name = $_GET['name'];

    if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {

        // get bytearray
        $gif = $GLOBALS["HTTP_RAW_POST_DATA"];

        // add headers for download dialog-box
        header('Content-Type: image/gif');
        header('Content-Length: '.strlen($gif ));
        header('Content-disposition:'.$method.'; filename="'.$name.'".gif');

        echo $gif ;

    }  else echo 'An error occured.';

    ?>

应该是这样。

请务必查看 Thibault Imbert's AS3 GIF Animation Encoding Class而这个 Web-Cam-Stop-Motion有趣的应用程序:)
Lee Felarca's SimpleFlvWriter也值得一看,具体取决于您的需求。

关于flash - 使用闪光灯捕获网络摄像头图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1350594/

相关文章:

html - 如何缩小 div 高度以适合图像

javascript - 嵌入的 Flash 对象不会捕捉到 Internet Explorer 上的点击(尽管 wmode)

flash - ActionScript 3 Profiler 和内存分析工具

java - 如何配置过滤器在 servlet 处理后工作?

HTTP 状态 404 - 请求的资源不可用

java - Red5 - SharedObject 中的 ArrayList 被损坏

java - 将 .jar 集成到 Flash 项目中

java - 无法访问JSP中的CSS和JavaScript文件

curl - 无法在 CentOS 上安装 Red5 的演示应用程序

linux - 初始化脚本进程 pid 不起作用