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 拍照的更多相关文章

  1. jQuery Webcam Plugin jscam.swf文件反编译工具使用说明

    jQuery webcam plugin是一个在ie,firefox,chrome下都可以用的摄像头摄像及拍照用的插件. (http://www.xarg.org/project/jquery-web ...

  2. 使用jQuery Uploadify在ASP.NET 上传附件

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...

  3. JQuery ajax调用asp.net的webMethod

    本文章转载:http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html 在vs2010中,用JQuery ajax调用as ...

  4. jQuery webcam plugin

    jQuery webcam plugin The jQuery webcam plugin is a transparent layer to communicate with a camera di ...

  5. JQuery Ajax调用asp.net后台方法

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: using System.Web.Scrip ...

  6. jQuery.ajax()调用asp.net后台方法

    利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法.介意方法名不要重名 建一个WebFormAjax名aspx文件 CS <%@ Page Language=" ...

  7. jQuery validate 根据 asp.net MVC的验证提取简单快捷的验证方式(jquery.validate.unobtrusive.js)

    最近在学习asp.netMVC,发现其中的验证方式书写方便快捷,应用简单,易学好懂. 验证方式基于jQuery的validate 验证方式,也可以说是对jQuery validate的验证方式的扩展, ...

  8. jQuery Grid With ASP.Net MVC

    jQuery Grid 能够在 ASP.NET MVC 中轻松地实现分页. 排序. 筛选以及 jQuery 插件网格中的 CRUD 操作. 具有以下特征: 时尚的表格数据呈现控件. JavaScrip ...

  9. [转]JQuery Ajax 在asp.net中使用总结

    本文转自:http://www.cnblogs.com/acles/articles/2385648.html 自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...

随机推荐

  1. Sqoop-1.4.4工具import和export使用详解

    转自:http://blog.csdn.net/wodatoucai/article/details/46343291 Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要 ...

  2. org.eclipse.core.resources.bak文件导致MyEclipse每次关闭时无法保存文件

    MyEclipse关闭时提示如下信息 Problems occurred while trying to save the state of the workbench. Internal Error ...

  3. Oracle的select检索数据

    --Select语法 select [distinct | All] select_list from table_list [where_clause] [group_by_clause] [Hav ...

  4. 重置 oschina 的CSS

    嗯, 目前只是改了一下OSChina的几个主要DIV宽度而以,还是很粗糙, 以后会慢慢改进的. ---------------------------------------------------- ...

  5. zoj1360/poj1328 Radar Installation(贪心)

    对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...

  6. PostgreSQL正则及模糊查询优化

    1.带前缀的模糊查询  ~'^abc' 可以使用btree索引优化 create index idx_info on table_name(info) 2.带后缀的模糊查询  ~'abc$' 可以使用 ...

  7. cocos2dx & cocostudio 实现模态对话框

    用cocos2dx实现模态对话框 http://www.cnblogs.com/mrblue/(转自于) ui部分使用了cocoStudio,注意这里没有实现怎么屏蔽其他的输入事件,其他的文档已经太多 ...

  8. [原]NYOJ-字符串替换-113

    大学生程序代写 /*http://acm.nyist.net/JudgeOnline/problem.php?pid=113 字符串替换 时间限制:3000 ms  |  内存限制:65535 KB  ...

  9. ACM学习历程—HDU1030 Delta-wave(数学)

    Description A triangle field is numbered with successive integers in the way shown on the picture be ...

  10. POJ2689:素数区间筛选

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15820   Accepted: 4202 D ...