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. Ubuntu application

    inkscape 矢量画图 gimp 类PS gpick 抓色工具 kdenlive 视频编辑 blender 3D Tweaks 外观设置 Krita 绘画工具 Fontforge 字体制作工具 B ...

  2. php gizp压缩传输js和css文件

    1. [代码][PHP]代码    <?php     /**     *  完整调用示例:     *  1.combine.php?t=j&b=public&fs=jslib ...

  3. C#统计目录中文件MD5值

    1. [代码]统计目录中文件MD5值 using System.IO;using System.Security.Cryptography;using System.Collections;using ...

  4. Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in class path resource [applicationContext.xml]

    Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined ...

  5. Sharepoint list webpart

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js&qu ...

  6. Java微信小程序开发_00_资源帖

    1.微信小程序开发:http://blog.csdn.net/column/details/13721.html?&page=1 2.微信小程序栏目:http://blog.csdn.net/ ...

  7. 备忘录One

    1.POI操作excel技术博客记录 2.SSH框架搭建记录 3.SSM框架搭建记录 4.文件上传下载记录 5.面试题整理

  8. QMainFrame类

    一.简介: 1.QMainFrame类提供了应用程序的主窗口,因为它可以添加菜单.工具条.状态栏和停靠窗口,同时也支持单文档窗口和多文档窗口,这是它和其他窗口不一样的地方. 2.QMainFrame窗 ...

  9. C++如何拒绝编译器自动生成的函数

    每一个class,编译器都会自动生成四个特殊成员函数: destructor(析构函数) default constructor(默认构造函数) copy constructor(copy构造函数) ...

  10. 洛谷3384&bzoj1036树链剖分

    值得注意的是: 一个点的子树是存在一起的...也就是说我们修改子树的时候只用... /********************************************************* ...