如何从 .Net 世界中的网站捕获相机图像?

发布于 2024-10-21 06:21:49 字数 246 浏览 8 评论 0原文

我有一个在线预订管理系统,需要捕获被预订到系统中的人员的图像。我目前支持从客户端计算机上的本地目录(例如 Facebook、LinkedIn 等)手动将图像上传到网站。但是,我还需要能够让客户端单击一个按钮,使他们能够使用连接到客户端计算机的相机(网络摄像头或其他方式)来拍摄快照并将其自动上传到服务器。

客户端环境是基于Windows的,我的开发环境是ASP.Net MVC 3。

是否有任何第三方ActiveX或Flash控件可以做到这一点?

I have an online booking management system that requires images to be captured of the people being booked into the system. I currently have support for uploading the images manually to the website from a local directory on the client machine (a la Facebook, LinkedIn, etc). However, I also need to be able for the client to click a button enabling them to use a camera (webcam or otherwise) hooked up to the client machine to take a snapshot and automatically upload it to the server.

The client environment is Windows based, and my development environment is ASP.Net MVC 3.

Are there any 3rd party ActiveX or Flash controls that can do this?

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

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

发布评论

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

评论(2

末が日狂欢 2024-10-28 06:21:49

我找到了一个第三方开源 Flash + JavaScript 库,它使这个过程相当简单,称为“ jpegcam'。

以下代码是针对 Asp.Net MVC 3 (Razor View + T4MVC) 构建的。


第 1 步:包含 javascript 库

<script type="text/javascript" src="@Url.Content("~/Scripts/jpegcam/htdocs/images.js")"></script>

第 2 步:设置 jpegcam 并连接必要的挂钩

<script type="text/javascript">
    webcam.set_api_url('@Url.Action(MVC.Images.Snapshot())');
    webcam.set_swf_url('@Url.Content("~/Scripts/jpegcam/htdocs/webcam.swf")');
    webcam.set_quality(90); // JPEG quality (1-100)
    webcam.set_shutter_sound(false, '@Url.Content("~/Scripts/jpegcam/htdocs/shutter.mp3")');
    webcam.set_hook('onComplete', 'upload_complete');

    document.write(webcam.get_html(320, 240));

    function upload() {
        webcam.freeze();  // Snapshot the image from the camera
        webcam.upload();  // POST the data w/ content type 'image/jpeg'
    }
    function upload_complete(response) {
        var json = jsonParse(response);
        if (json.Redirect) {
            window.location.replace(json.Redirect);
        } else if (json.Error) {
            Notifier.Error('Error', json.Error.Message);
            webcam.reset();
        } else {
            Notifier.Error('Error', 'An unknown error has occurred.');
            webcam.reset();
        }
    }
</script>

注意:webcam.set_api_url() 调用设置发布网址。

第 3 步:连接视图中的按钮

<p class="actions">
    <input id="capture-configure" class="secondary-button" type="button" value="Configure..." onclick="webcam.configure()" />
    <input id="capture-submit" class="primary-button" type="button" value="Snap Mugshot" onclick="upload()" />
    <span class="alternate">
        or <a class="cancel" href="@Url.Action(MVC.Images.View())">Cancel</a>
    </span>
</p>

第 4 步:创建控制器操作以服务 POST

[HttpPost]
public virtual ActionResult Snapshot()
{
    var image = new System.Web.Helpers.WebImage(Request.InputStream);
    // Do fun, amazing things with the jpeg image
    return RedirectToAction(MVC.Images.View());
}

注意:System.Web.Helpers.WebImage 是“microsoft-web-helpers”NuGet 包的一部分。

I found a 3rd party open-source Flash + JavaScript library that made this fairly simple called 'jpegcam'.

The following code is built against Asp.Net MVC 3 (Razor View + T4MVC).


Step 1: Include the javascript library

<script type="text/javascript" src="@Url.Content("~/Scripts/jpegcam/htdocs/images.js")"></script>

Step 2: Setup jpegcam and wire up the necessary hooks

<script type="text/javascript">
    webcam.set_api_url('@Url.Action(MVC.Images.Snapshot())');
    webcam.set_swf_url('@Url.Content("~/Scripts/jpegcam/htdocs/webcam.swf")');
    webcam.set_quality(90); // JPEG quality (1-100)
    webcam.set_shutter_sound(false, '@Url.Content("~/Scripts/jpegcam/htdocs/shutter.mp3")');
    webcam.set_hook('onComplete', 'upload_complete');

    document.write(webcam.get_html(320, 240));

    function upload() {
        webcam.freeze();  // Snapshot the image from the camera
        webcam.upload();  // POST the data w/ content type 'image/jpeg'
    }
    function upload_complete(response) {
        var json = jsonParse(response);
        if (json.Redirect) {
            window.location.replace(json.Redirect);
        } else if (json.Error) {
            Notifier.Error('Error', json.Error.Message);
            webcam.reset();
        } else {
            Notifier.Error('Error', 'An unknown error has occurred.');
            webcam.reset();
        }
    }
</script>

Note: The webcam.set_api_url() call sets up the POST url.

Step 3: Wire up the buttons in the view

<p class="actions">
    <input id="capture-configure" class="secondary-button" type="button" value="Configure..." onclick="webcam.configure()" />
    <input id="capture-submit" class="primary-button" type="button" value="Snap Mugshot" onclick="upload()" />
    <span class="alternate">
        or <a class="cancel" href="@Url.Action(MVC.Images.View())">Cancel</a>
    </span>
</p>

Step 4: Create the controller action to service the POST

[HttpPost]
public virtual ActionResult Snapshot()
{
    var image = new System.Web.Helpers.WebImage(Request.InputStream);
    // Do fun, amazing things with the jpeg image
    return RedirectToAction(MVC.Images.View());
}

Note: System.Web.Helpers.WebImage is part of the 'microsoft-web-helpers' NuGet package.

依 靠 2024-10-28 06:21:49

也许您可以使用 Silverlight 4 来实现此目的?版本 4 支持网络摄像头。

以下是 SilverlightShow.net 上的教程

Maybe you could use Silverlight 4 for this? Version 4 comes with support for webcams.

Here's a tutorial at SilverlightShow.net

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