使用闪光灯捕获网络摄像头图像? [英] use flash capture webcam image?

查看:17
本文介绍了使用闪光灯捕获网络摄像头图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there any open source flash utility that i can embed on a webpage and use it to capture user webcam image or short duration clips and do "POST" to my server servlet ? i do not looking for streaming video and so i do not need red5 or flash server. can you folks elaborate ...?

推荐答案

这听起来很适合 Thibault Imbert 的 AS3 GIF 动画编码类.大约 2 年前,我在大学的一个项目中使用了它.您可以在此处查看.在我看来,您将有 3 个步骤:

This sounds like a good candidate for Thibault Imbert's AS3 GIF Animation Encoding Class. I've used it about 2 years ago for a project at University. You can check it out here. In my opinion you would have 3 steps:

//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 的 AS3 GIF 动画编码类和这个 Web-Cam-Stop-Motion 有趣的应用程序 :)Lee Felarca 的 SimpleFlvWriter 也值得一看,取决于您的需求.

Make sure you check out Thibault Imbert's AS3 GIF Animation Encoding Class and this Web-Cam-Stop-Motion fun app :) Lee Felarca's SimpleFlvWriter is worth looking at as well, depending on your needs.

这篇关于使用闪光灯捕获网络摄像头图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆