jQuery网络摄像头插件,带有ASP.NET 4.0,无法在服务器上保存捕获的图像



我使用jQuery网络摄像头插件与ASP.NET 4.0。我想捕获图像并将其保存在服务器上。我到达了可以看到网络摄像头的地步,单击照片并将其发送到服务器端。但是我不明白如何将已发布的图像保存在服务器上。

我尝试将Inputstream保存到文件中,但它说其无效的映像。请帮助。

aspx代码

<script type="text/javascript">
    $(function () {
        $("#webcam").webcam({
            width: 100,
            height: 100,
            mode: "save",
            swffile: 'jscam.swf'
        });
    });
    function capture() {
        webcam.capture();
        webcam.save('SavePhoto.aspx');
    }
</script>

<div id="webcam"></div>
<input type="button" id="takePhoto" onclick="capture();" value="Capture" />

在大量搜索之后,我最终得到了这个解决方案。只需将Request.InputStream传递到功能。就我而言,我必须创建缩略图副本,所以我需要System.Drawing.Image

    Public Function getImage(SrcStream As System.IO.Stream) As System.Drawing.Image
    'This function returns Image from InputStream
    Dim dump As String
    Using reader = New StreamReader(SrcStream)
        dump = reader.ReadToEnd()
    End Using
    ''To save as a file.
    'Dim path = Server.MapPath("/test.jpg")
    'System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump))
    Return System.Drawing.Image.FromStream(New System.IO.MemoryStream(String_To_Bytes2(dump)))
End Function
    Private Function String_To_Bytes2(strInput As String) As Byte()
    Dim numBytes As Integer = (strInput.Length) / 2
    Dim bytes As Byte() = New Byte(numBytes - 1) {}
    For x As Integer = 0 To numBytes - 1
        bytes(x) = Convert.ToByte(strInput.Substring(x * 2, 2), 16)
    Next
    Return bytes
    End Function

(希望您可以将其转换为C#)

最新更新