简体   繁体   English

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

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

I am using JQuery webcam plugin with asp.net 4.0. 我在ASP.NET 4.0中使用JQuery网络摄像头插件。 I want to capture image and save it on server. 我想捕获图像并将其保存在服务器上。 I reached to the point where I can see webcam, click photo and send it to server side. 我到达可以看到网络摄像头的位置,单击照片并将其发送到服务器端。 But I am not understanding how to save that posted image on server. 但是我不明白如何将发布的图像保存在服务器上。

I tried saving InputStream to the file but it is saying its not valid image. 我尝试将InputStream保存到文件中,但是它表示无效的图像。 please help. 请帮忙。

aspx code 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" />

After lot of search I ended up with this solution. 经过大量搜索,我最终得到了这种解决方案。 Just pass Request.InputStream to the function. 只需将Request.InputStream传递给函数即可。 In my case I have to create a thumbnail copy so I needed System.Drawing.Image 就我而言,我必须创建一个缩略图副本,因此需要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

(hope you can convert it to c#) (希望您可以将其转换为C#)

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

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