首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否使用闪存捕获网络摄像头图像?

是否使用闪存捕获网络摄像头图像?
EN

Stack Overflow用户
提问于 2009-08-29 05:56:25
回答 1查看 7.1K关注 0票数 4

有没有什么开源的flash工具,我可以把它嵌入到网页上,用它来捕捉用户的摄像头图像或短持续时间的剪辑,并将其"POST“到我的服务器servlet?我不寻找流视频,所以我不需要red5或闪存服务器。你们能详细说明...吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-08-29 10:37:57

这听起来是Thibault Imbert's AS3 GIF Animation Encoding Class的一个很好的候选者。大约两年前,我在大学的一个项目中使用过它。你可以在here上查看。在我看来,你应该有3个步骤:

代码语言:javascript
复制
//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 fun应用程序:) Lee Felarca's SimpleFlvWriter也值得一看,这取决于您的需求。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1350594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档