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. LINQ 学习路程 -- 开篇

    Enumerable: Queryable:

  2. 程序以html形式发送邮件注意问题

    1.样式要写在内部,不要单独定义样式 2.div 使用背景图片在有些浏览器中出不来这时候需要用: <table style="width: 640px" cellpaddin ...

  3. hash算法打散存储文件

    1.首先,为防止一个目录下面出现太多文件,所以使用hash算法打散存储 举例代码: int hashcode = filename.hashCode();//得到hashCode int dir1 = ...

  4. Twitter的流处理器系统Heron——升级的storm,可以利用mesos来进行资源调度

    2011年,Twitter发布了开源的分布式流计算系统Storm.四年后,随着用户数量的急剧增加,Twitter每天要处理的事件已经增加到十亿以上.Storm系统应对如此庞大而复杂多样的流数据变得十分 ...

  5. php-fpm进程内存泄漏

    线上服务器内存报警 线上web8G内存的服务器,内存几乎吃光,top查看,发现php-fpm进程每个都是几十M,php-fpm配置static, 一共150个 解决 排除过程中,其他机器相同配置都没有 ...

  6. tensorflow中张量(tensor)的属性——维数(阶)、形状和数据类型

    tensorflow的命名来源于本身的运行原理,tensor(张量)意味着N维数组,flow(流)意味着基于数据流图的计算,所以tensorflow字面理解为张量从流图的一端流动到另一端的计算过程. ...

  7. Gym - 100570C: Subrect Query (巧妙的单调队列)

    De Prezer loves rectangles.He has a n × m rectangle which there is a number in each of its cells. We ...

  8. bzoj 1819: 电子字典 Trie

    题目: Description 人们在英文字典中查找某个单词的时候可能不知道该单词的完整拼法,而只知道该单词的一个错误的近似拼法,这时人们可能陷入困境,为了查找一个单词而浪费大量的时间.带有模糊查询功 ...

  9. 51nod 1486 大大走格子——容斥

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1486 已知起点到某个障碍点左上角的所有点的不经过障碍的方案数,枚举 ...

  10. bzoj 2632 [ neerc 2011 ] Gcd guessing game —— 贪心

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2632 官方题解:http://neerc.ifmo.ru/archive/2011/neer ...