使用asp.net 4.0的JQuery网络摄像头插件,无法在服务器上保存捕获的图像

时间:2014-02-01 06:16:20

标签: c# jquery asp.net webcam

我正在使用asp.net 4.0的JQuery网络摄像头插件。我想捕获图像并将其保存在服务器上。我到达了可以看到网络摄像头的位置,点击照片并将其发送到服务器端。但我不明白如何在服务器上保存该发布的图像。

我尝试将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" />

1 个答案:

答案 0 :(得分:0)

经过大量搜索,我最终得到了这个解决方案。只需将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#)