使用 jquery.webcam 进行asp.net 拍照
HTML 代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="JqueryCamera.index" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title></title>
<script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.1.3/jquery.js"></script>
<script type="text/javascript" src="js/jquery.webcam.js"></script>
</head>
<body> <script type="text/javascript">
$(document).ready(function () {
var image = new Array();
var ctx = null;
var pos = 0;
var w = 320;
var h = 240;
$("#webcam").webcam({
width: 320,
height: 240,
mode: "callback",
swffile: "/js/jscam_canvas_only.swf",
onTick: function (remain) { },
onSave: function (data) {
image.push(data);
pos += 4 * w;
if (pos == 4 * w * h) {
$.post("CamPost.ashx", { w: w, h: h, pix: image.join('|') }, function (msg) {
$("#flash").attr('src', msg);
$("#txt_img_path").val(msg);
pos = 0;
image = new Array();
});
}
},
onCapture: function () { webcam.save(); },
onLoad: function () {
var x = 0;
var cams = webcam.getCameraList();
for (var i in cams) {
jQuery("#cams").append("设备信息:" + cams[i] + 设备信);
x++;
}
jQuery("#Div1").append("拥有设备数:" + x + "");
}
});
});
</script>
<div id="cam" style="width: 320px; height:240px; border: solid 1px #ddd; float:left;">
<div id="camBox">
<div id="webcam">
</div>
</div> </div> <div style="width: 320px; height: 240px; border: 1px solid #ddd; float:left;"> <img id="flash" /> </div>
<div style="clear: both;">
</div>
<input type="button" value="拍照" id="btn_pz" name="btn_pz" onclick="webcam.capture()"/><br />
<input type="text" id="txt_img_path" style=" width:320px;"/>
<div id="cams"></div>
<div id="Div1"></div>
</body>
</html>
CamPost.ashx 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace JqueryCamera
{
/// <summary>
/// CamPost 的摘要说明
/// </summary>
public class CamPost : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
string wbepath = "";
context.Response.ContentType = "text/plain";
DateTime dt = DateTime.Now;
string fileName = dt.ToString("yyyyMMdd_HHmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".jpg";
if (context.Request["pix"] != null )
{
if (!string.IsNullOrEmpty(context.Request["w"]) && !string.IsNullOrEmpty(context.Request["h"]) && !string.IsNullOrEmpty(context.Request["pix"])) // && !string.IsNullOrEmpty(context.Request["planid"]) && !string.IsNullOrEmpty(context.Request["examkey"]
{
string planid = DateTime.Now.ToString("yyyyMMdd")+ "";
string examkey = context.Request["examkey"];
string width = context.Request["w"];
string height = context.Request["h"];
string pix = context.Request["pix"];
int w = int.Parse(width);
int h = int.Parse(height);
string savePath = context.Server.MapPath("~/UpLoad/Cam_Img/" + planid + "/");
try
{ System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(w, h);
string[] rows = pix.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < rows.Length; i++)
{
string[] col = rows[i].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < col.Length; j++)
{
System.Drawing.Color color = System.Drawing.Color.FromArgb(Convert.ToInt32(col[j]));
System.Drawing.Color reColor = System.Drawing.Color.FromArgb(255, color);
bmap.SetPixel(j, i, reColor);
}
}
System.IO.DirectoryInfo dirPath = new System.IO.DirectoryInfo(savePath);
if (!dirPath.Exists)
{
dirPath.Create();
} savePath += fileName;
bmap.Save(savePath);
}
catch (Exception e)
{
} wbepath = "/UpLoad/Cam_Img/" + planid + "/" + fileName;
context.Response.Write(wbepath);
context.Response.End();
}
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}
使用 jquery.webcam 进行asp.net 拍照的更多相关文章
- jQuery Webcam Plugin jscam.swf文件反编译工具使用说明
jQuery webcam plugin是一个在ie,firefox,chrome下都可以用的摄像头摄像及拍照用的插件. (http://www.xarg.org/project/jquery-web ...
- 使用jQuery Uploadify在ASP.NET 上传附件
Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...
- JQuery ajax调用asp.net的webMethod
本文章转载:http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html 在vs2010中,用JQuery ajax调用as ...
- jQuery webcam plugin
jQuery webcam plugin The jQuery webcam plugin is a transparent layer to communicate with a camera di ...
- JQuery Ajax调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: using System.Web.Scrip ...
- jQuery.ajax()调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.介意方法名不要重名 建一个WebFormAjax名aspx文件 CS <%@ Page Language=" ...
- jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)
最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...
- jQuery Grid With ASP.Net MVC
jQuery Grid 能够在 ASP.NET MVC 中轻松地实现分页. 排序. 筛选以及 jQuery 插件网格中的 CRUD 操作. 具有以下特征: 时尚的表格数据呈现控件. JavaScrip ...
- [转]JQuery Ajax 在asp.net中使用总结
本文转自:http://www.cnblogs.com/acles/articles/2385648.html 自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...
随机推荐
- castle windsor学习-----Registering components one-by-one 注册类型
1.在容器中注册一个类型 container.Register( Component.For<IMyService>() .ImplementedBy<MyServiceImpl&g ...
- TF卡
1.我的手机 64G 2.冬冬手机 16G 3.茜茜收音机 8G(创见) 4.父 手机 8G(Kingston) 5. 6. 7.
- Subnet Pools and Address Scopes
Why is IPAM important for Neutron? •No VM connectivity without a valid IP assigned •Duplicate subne ...
- python第六篇:Python复制超大文件、复制二进制文件
Python文件复制 # 写程序实现复制文件的功能 # 要求: # 1. 源文件路径和目标文件路径需要手动输入 # 2. 要考虑文件关闭的问题 # 3. 要考虑复制超大文件的问题 # 4. 要能复制二 ...
- memset和memcopy用法
void *memset(void *s, int ch, size_t n); 函数解释:将s中前n个字节 (typedef unsigned int size_t)用 ch 替换并返回 s . m ...
- HTML5学习记录——3
HTML媒体 1.HTML多媒体 视频格式 .avi 微软开发 .wmv 微软开发 .mpg .mpeg .mov 苹果公司开发 .rm .ram 允许低带宽的视频流 .swf .fl ...
- pandas 学习 —— pivot table
0. DataFrame 的 index.columns.values >> df = pd.DataFrame(np.arange(6).reshape(3, 2), index=['o ...
- 打包AAC码流到FLV文件
AAC编码后数据打包到FLV很简单. 1. FLV音频Tag格式 字节位置 意义0x08, ...
- YNOI2016 这是我自己的发明
看到这个标题立刻想到:. “绝地科学家,八倍不屏息啊,八百里外把头打啊...” 首先我们发现如果只考虑第二个操作,这棵树就是假的,我们可以直接莫队解决 如果考虑换根的话...可以把一个操作换成小于等于 ...
- AngularJS方法 —— angular.copy
描述: 复制一个对象或者一个数组(好吧,万物皆对象,数组也是一个对象). 如果省略了destination,一个新的对象或数组将会被创建出来: 如果提供了destination,则source对象中的 ...