使用 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的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...
随机推荐
- matlab查找最临近搜索knnsearch
Idx = knnsearch(X,Y) finds the nearest neighbor in X for each query point in Y and returns the indic ...
- 【原创】cocos2d-x3.9蓝牙开发之蓝牙开启
本人第一次搞android开发,很多东西都是只知道一点点,然而都没怎么实践过,所以这次就边学边做自己想要的功能,可能会花较长时间,不过肯定是值得的,有用词或哪里说得不对的请指正. 我自己有androi ...
- 1W字看懂互联网知识经济
互联网知识经济,发生关键变化的不是知识,而是经济. 今天和大家分享方军老师的新书<付费:互联网知识经济的兴起>.这本书是一个老互联网人看新知识经济,很有意思的视角在于,以互联网的发展为节点 ...
- gethub的安装
下载地址: windows的下载地址 https://gitforwindows.org/ 一.安装 win下的安装注意要点: 1.环境变量 2.文件结束符如何处理(windows下/r/n,linu ...
- sqlserver 新建只读权限用户
1,新建只能访问某一个表的只读用户. --添加只允许访问指定表的用户:execsp_addlogin'用户名','密码','默认数据库名' --添加到数据库execsp_grantdbaccess'用 ...
- HDU 6231 (K-th Number)
题目链接:https://cn.vjudge.net/problem/HDU-6231 思路:二分+双指针: #include <stdio.h> #include <iostrea ...
- python 标准库 —— 线程与同步(threading、multiprocessing)
1. 创建线程 使用 os 下的 fork() 函数调用(仅限 Unix 系统) import os print('current process (%s) starts ...' % (os.get ...
- OpenCV - Android Studio 中集成Opencv环境(不包含opencv_contrib部分)
OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉库,支持的运行环境也是非常的多,这篇文章主要讲的是Android环境集成OpenCV(IDE是Android Studio,我想Eclip ...
- CH5103 [NOIP2008]传纸条[线性DP]
给定一个 N*M 的矩阵A,每个格子中有一个整数.现在需要找到两条从左上角 (1,1) 到右下角 (N,M) 的路径,路径上的每一步只能向右或向下走.路径经过的格子中的数会被取走.两条路径不能经过同一 ...
- 移植memtester到android平台
硬件搭建起来能进入系统,首要就是测试内存的稳定性,需要一款内存测试工具. 一般都是选择memtester这款linux软件,下载地址如下:http://pyropus.ca/software/memt ...