如何在ASP.NET中通过网络摄像头捕获时更改图像的默认高度和宽度 [英] How to change the default height and width of image while capturing through webcam in ASP.NET
本文介绍了如何在ASP.NET中通过网络摄像头捕获时更改图像的默认高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开展一个用户将通过网络摄像头拍摄照片的项目。然后它会在点击捕获按钮时保存在文件夹中。
用于网络摄像头,我正在使用jquery插件 - jquery.webcam.js
但是当点击捕获按钮时,它会捕获320 X 200尺寸的图像。
我正在使用高清网络摄像头拍摄图像。
如何在高维位置更改此图片。
求助。
我尝试了什么:
i am working on a project where user will capture his photo through webcam. and then it will save in a folder when click on the capture button.
for webcam, i am using the jquery plugin - jquery.webcam.js
but when click on the capture button, it capture the image in 320 X 200 Dimensions.
i am using the hd webcam for capturing images.
how to change this image in high dimensions.
please help.
What I have tried:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src='<%=ResolveUrl("~/Webcam_Plugin/jquery.webcam.js") %>' type="text/javascript"></script>
<script type="text/javascript">
var pageUrl = '<%=ResolveUrl("~/VB.aspx") %>';
$(function () {
jQuery("#webcam").webcam({
width: 1024,
height: 768,
mode: "save",
swffile: '<%=ResolveUrl("~/Webcam_Plugin/jscam.swf") %>',
debug: function (type, status) {
$('#camStatus').append(type + ": " + status + '<br /><br />');
},
onSave: function (data) {
$.ajax({
type: "POST",
url: pageUrl + "/GetCapturedImage",
data: '',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
$("[id*=imgCapture]").css("visibility", "visible");
$("[id*=imgCapture]").attr("src", r.d);
},
failure: function (response) {
alert(response.d);
}
});
},
onCapture: function () {
webcam.save(pageUrl);
}
});
});
function Capture() {
webcam.capture();
return false;
}
</script>
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
Live Camera
</td>
<td>
</td>
<td align="center">
Captured Picture
</td>
</tr>
<tr>
<td>
<div id="webcam">
</div>
</td>
<td>
</td>
<td>
<asp:Image ID="imgCapture" runat="server" Style="visibility: hidden; width: 320px;
height: 240px" />
</td>
</tr>
</table>
<br />
<asp:Button ID="btnCapture" Text="Capture" runat="server" OnClientClick="return Capture();" />
<br />
<span id="camStatus"></span>
</form>
</body>
</html>
Imports System.IO
Imports System.Web.Services
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
If Request.InputStream.Length > 0 Then
Using reader As New StreamReader(Request.InputStream)
Dim hexString As String = Server.UrlEncode(reader.ReadToEnd())
Dim imageName As String = DateTime.Now.ToString("dd-MM-yy hh-mm-ss")
Dim imagePath As String = String.Format("~/Captures/{0}.png", imageName)
File.WriteAllBytes(Server.MapPath(imagePath), ConvertHexToBytes(hexString))
Session("CapturedImage") = ResolveUrl(imagePath)
End Using
End If
End If
End Sub
Private Shared Function ConvertHexToBytes(hex As String) As Byte()
Dim bytes As Byte() = New Byte(hex.Length / 2 - 1) {}
For i As Integer = 0 To hex.Length - 1 Step 2
bytes(i / 2) = Convert.ToByte(hex.Substring(i, 2), 16)
Next
Return bytes
End Function
<WebMethod(EnableSession:=True)> _
Public Shared Function GetCapturedImage() As String
Dim url As String = HttpContext.Current.Session("CapturedImage").ToString()
HttpContext.Current.Session("CapturedImage") = Nothing
Return url
End Function
End Class
推荐答案
( function () {
jQuery( #webcam)。webcam({
width: 1024 ,
height: 768 ,
模式: save,
swffile:' <%= ResolveUrl(〜/ Webcam_Plugin / jscam.swf)%>',
debug: function (类型,状态){
(function () { jQuery("#webcam").webcam({ width: 1024, height: 768, mode: "save", swffile: '<%=ResolveUrl("~/Webcam_Plugin/jscam.swf") %>', debug: function (type, status) {
(' #camStatus').append(type + : + status + ' < br />< br />');
},
onSave: function (data){
('#camStatus').append(type + ": " + status + '<br /><br />'); }, onSave: function (data) {
.ajax({
类型: POST,
url:pageUrl + / GetCapturedImage,
data:' ',
contentType: application / json; charset = utf -8,
dataType: json,
成功:功能(r){
.ajax({ type: "POST", url: pageUrl + "/GetCapturedImage", data: '', contentType: "application/json; charset=utf-8", dataType: "json", success: function (r) {
这篇关于如何在ASP.NET中通过网络摄像头捕获时更改图像的默认高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文