I am using JQuery webcam plugin with asp.net 4.0. 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. please help.
aspx code
<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. In my case I have to create a thumbnail copy so I needed 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#)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.