我有一种方法可以从网络摄像头捕获图像并将该图像保存到服务器上的文件夹中。但是,当允许访问凸轮时,它仅显示白屏。此外,保存的图像是白屏。
有什么想法阻止了潮流?
查看代码:
@{
ViewBag.Title = "Index";
}
@section scripts
{
<script src="@Url.Content("~/Scripts/jquery.webcam.js")">
</script>
<script>
$("#Camera").webcam({
width: 320,
height: 240,
mode: "save",
swffile: "@Url.Content("~/Scripts/jscam.swf")",
onTick: function () { },
onSave: function () {
},
onCapture: function () {
webcam.save("@Url.Content("~/Home/Capture")/");
},
debug: function () { },
onLoad: function () { }
});
</script>
}
<h2>Index</h2>
<input type="button" value="Shoot!" onclick="webcam.capture();" />
<div id="Camera"></div>
控制器代码:
public void Capture()
{
var stream = Request.InputStream;
string dump;
using (var reader = new StreamReader(stream))
dump = reader.ReadToEnd();
var path = Server.MapPath("~/test.jpg");
System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));
}
private byte[] String_To_Bytes2(string strInput)
{
int numBytes = (strInput.Length) / 2;
byte[] bytes = new byte[numBytes];
for (int x = 0; x < numBytes; ++x)
{
bytes[x] = Convert.ToByte(strInput.Substring(x * 2, 2), 16);
}
return bytes;
}