从网络摄像头捕获图像并保存

问题描述 投票:0回答:2

大家好,我正在尝试保存从我的网络摄像头拍摄的照片。 我实际上使用这个代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class ImageConversions : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CreatePhoto();
    }

    void CreatePhoto()
    {
        try
        {

            string strPhoto = Request.Form["imageData"]; //Get the image from flash file
            byte[] photo = Convert.FromBase64String(strPhoto);



           FileStream fs = new FileStream("C:\\Webcam.jpg", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter br = new BinaryWriter(fs);
            br.Write(photo);
            br.Flush();
            br.Close();
            fs.Close();
        }
        catch (Exception Ex)
        {

        }
    }
}

应用程序运行,我看到图像,我单击捕获按钮,直到这里才出现错误,但是但是......没有保存图像我从下载了示例 这里:http://www.dotnetspider.com/resources/38150-Capture-save-images-from-Web-camera.aspx(检查附件)

asp.net image save webcam
2个回答
0
投票

更改路径..我也遇到了同样的问题.. 您的C盘安全级别高, 将路径更改为“D:\Webcam.jpg”即可工作


0
投票

试试这篇文章。效果非常好。但是,当未连接网络摄像头时,我无法使用自定义消息。它会给出自动生成的错误消息。

网络摄像头库dotnet

© www.soinside.com 2019 - 2024. All rights reserved.