繁体   English   中英

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

[英]JQuery webcam plugin with asp.net 4.0, not able to save captured image on server

我在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" />

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM