簡體   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