我正在寻找创建一个 ASP.Net 网站,用户可以在其中从那里的网络摄像头捕获图像并将其保存到我服务器上的数据库中。我曾尝试使用 TWAIN,但似乎找不到任何支持此功能的新相机。尝试使用 Silverlight 和 WIA 时也是如此。有没有人在这方面取得任何成功?
客户端计算机将配备我推荐的任何网络摄像头,因此如果您知道可行的型号,请分享。我已经尝试过 Microsoft LifeCam 和 Logitech,但都没有成功。
如果你已经这样做了,或者现在我真的很感激一些帮助。谢谢你的时间。
如果您的目标是较新的浏览器(那些支持 WebRTC getUserMedia 方法的浏览器),那么 Photobooth.js 可能是您的选择。
引自 WebMonkey:“吸引我们眼球的最新 WebRTC 热点是开发人员 Wolfram Hempel 的 Photobooth.js,这是一个用于与设备相机配合使用的 JavaScript 库。”
http://www.webmonkey.com/2012/12/add-an-html5-webcam-to-your-site-with-photobooth-js/
和库本身:
http://wolframhempel.com/2012/12/02/photobooth-js/
希望对你有帮助!
asp.net 是一种服务器端技术,无法连接到客户端网络摄像头。您的浏览器高度沙盒化,不太可能允许访问用户的网络摄像头。
考虑构建 Flash 或 Silverlight 组件来访问网络摄像头。
对此的例外是,在许多移动平台上,浏览器可以通过<input type="file" />标签访问相机和图片存储。这在 Android 上已经有一段时间了,现在是 Safari v6 的一个选项。我不知道任何允许直接访问附加网络摄像头的桌面浏览器。
奖励解决方法是让用户拍照,然后通过文件上传访问它们。
通过让用户在计算机上安装 Google Chrome Frame,然后使用 canvas 标签获取图像,我能够完成我想要的。效果很好,这里有一些示例代码:
<div>
<p id="status" style="color:red">
<noscript>JavaScript is disabled.</noscript>
</p>
<table>
<tr>
<td>
<input id="btnTakePicture" type="button" value="Take Picture"; />
</td>
<td>
<input id="btnSave" type="button" value="Save Picture"; />
</td>
</tr>
</table>
<asp:Button ID="btnSavePicture" runat="server" Text="HiddenSave" OnClick="btnSavePicture_Click" CssClass="hiddencol" />
<asp:Panel ID="pnlHide" runat="server" style="display:none" >
<textarea id="eventdata" rows="18" cols="1" style="width: 100%" runat="server"></textarea>
</asp:Panel>
<script type="text/javascript">
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
var webcam = (function () {
var video = document.createElement('video'),
photo = document.createElement('canvas');
function play() {
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true, audio: true, toString: function () { return "video,audio"; } }, onSuccess, onError);
} else {
changeStatus('getUserMedia is not supported in this browser.', true);
}
}
function onSuccess(stream) {
var source;
if (window.webkitURL) {
source = window.webkitURL.createObjectURL(stream);
} else {
source = stream; // Opera and Firefox
}
video.autoplay = true;
video.src = source;
changeStatus('Connected.', false);
}
function onError() {
changeStatus('Please accept the getUserMedia permissions! Refresh to try again.', true);
}
function changeStatus(msg, error) {
var status = document.getElementById('status');
status.innerHTML = msg;
status.style.color = (error) ? 'red' : 'green';
}
// allow the user to take a screenshot
function setupPhotoBooth() {
//var takeButton = document.createElement('button');
var takeButton = document.getElementById('btnTakePicture');
//takeButton.innerText = 'Take Picture';
takeButton.addEventListener('click', takePhoto, true);
//document.body.appendChild(takeButton);
//var saveButton = document.createElement('button');
var saveButton = document.getElementById('btnSave');
//saveButton.id = 'btnSave';
//saveButton.innerText = 'Save Picture';
saveButton.disabled = true;
saveButton.addEventListener('click', savePhoto, true);
//document.body.appendChild(saveButton);
}
function takePhoto() {
// set our canvas to the same size as our video
photo.width = video.width;
photo.height = video.height;
var context = photo.getContext('2d');
context.drawImage(video, 0, 0, photo.width, photo.height);
// allow us to save
var saveButton = document.getElementById('btnSave');
saveButton.disabled = false;
var data = photo.toDataURL("image/png");
data = data.replace("image/png", "");
document.getElementById("<%= eventdata.ClientID %>").value = data;
}
function savePhoto() {
// var data = photo.toDataURL("image/png");
// data = data.replace("image/png", "image/octet-stream");
// document.getElementById("<%= eventdata.ClientID %>").value = data;
// document.location.href = data;
SendBack();
}
return {
init: function () {
changeStatus('Please accept the permissions dialog.', true);
video.width = 320;
video.height = 240;
document.body.appendChild(video);
document.body.appendChild(photo);
navigator.getUserMedia || (navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia);
play();
setupPhotoBooth();
} ()
}
})();
function SendBack() {
var btn = document.getElementById("<%= btnSavePicture.ClientID %>");
btn.click();
}
</script>
</div>