急求:jsp应用中如何使用摄像头拍照并保存数据库中
本人现在做一个学籍管理系统:
想做到:在一个JSP页面中,有个小窗口可以使用摄像头看到学生,并在学生摆正姿势后,点击一个按钮,把他(她)的照片拍下,点击保存保存在该学生的学籍中。
(就像计算机一级考试那个现场数码照像)
请问:怎么解决?
谢谢!!!
[解决办法]
关注。。。。。
[解决办法]
不知道
[解决办法]
我估计,要通过JNI去调
[解决办法]
不会,帮up
[解决办法]
从Java来做这个, 我觉得有难度...
应该是从驱动下手吧
[解决办法]
http://community.csdn.net/Expert/topic/5425/5425514.xml?temp=.311886
看看这个里面
[解决办法]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
namespace CapTureMovie
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button BtnCapTure;
private System.Windows.Forms.Panel panel_Vedio;
private int hHwnd;
private System.Windows.Forms.Button BtnStop;
private System.Windows.Forms.Label LbSysMsg;
private System.Windows.Forms.Button button1;
public struct videohdr_tag
{
public byte[] lpData;
public int dwBufferLength;
public int dwBytesUsed;
public int dwTimeCaptured;
public int dwUser;
public int dwFlags;
public int[] dwReserved;
}
public delegate bool CallBack(int hwnd, int lParam);
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
[DllImport( "avicap32.dll ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
[DllImport( "avicap32.dll ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern bool capGetDriverDescriptionA(short wDriver, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszVer, int cbVer);
[DllImport( "user32 ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern bool DestroyWindow(int hndw);
[DllImport( "user32 ", EntryPoint= "SendMessageA ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
[DllImport( "user32 ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport( "vfw32.dll ")]
public static extern string capVideoStreamCallback(int hwnd,videohdr_tag videohdr_tag);
[DllImport( "vicap32.dll ", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)]
public static extern bool capSetCallbackOnFrame(int hwnd,string s);
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[解决办法]
首先到sun下载最新的jmf,然后安装。http://java.sun.com/products/java-media/jmf/index.jsp
然后,说一下需求
1. 用摄像头拍照
2. 在文本框输入文件名
3. 按下拍照按钮,获取摄像头内的图像
4. 在拍下的照片上有一红框截取固定大小的照片。
5. 保存为本地图像为jpg格式,不得压缩画质
技术关键,相信也是大家最感兴趣的部分也就是如何让一个摄像头工作,并拍下一张照片了。
利用jmf,代码很简单:
//利用这三个类分别获取摄像头驱动,和获取摄像头内的图像流,获取到的图像流是一个swing的component组件类
public static player player = null;
private capturedeviceinfo di = null;
private medialocator ml = null;
//文档中提供的驱动写法,为何这么写我也不知:)
string str1 = "vfw:logitech usb video camera:0 ";
string str2 = "vfw:microsoft wdm image capture (win32):0 ";
di = capturedevicemanager.getdevice(str2);
ml = di.getlocator();
try
{
player = manager.createrealizedplayer(ml);
player.start();
component comp;
if ((comp = player.getvisualcomponent()) != null)
{
add(comp, borderlayout.north);
}
}
catch (exception e)
{
e.printstacktrace();
}
接下来就是点击拍照,获取摄像头内的当前图像。
代码也是很简单:
private jbutton capture;
private buffer buf = null;
private buffertoimage btoi = null;
private imagepanel imgpanel = null;
private image img = null;
private imagepanel imgpanel = null;
jcomponent c = (jcomponent) e.getsource();
if (c == capture)//如果按下的是拍照按钮
{
framegrabbingcontrol fgc =(framegrabbingcontrol) player.getcontrol( "javax.media.control.framegrabbingcontrol ");
buf = fgc.grabframe(); // 获取当前祯并存入buffer类
btoi = new buffertoimage((videoformat) buf.getformat());
img = btoi.createimage(buf); // show the image
imgpanel.setimage(img);
}
保存图像的就不多说了,以下为示例代码
bufferedimage bi = (bufferedimage) createimage(imgwidth, imgheight);
graphics2d g2 = bi.creategraphics();
g2.drawimage(img, null, null);
fileoutputstream out = null;
try
{
out = new fileoutputstream(s);
}
catch (java.io.filenotfoundexception io)
{
system.out.println( "file not found ");
}
jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
jpegencodeparam param = encoder.getdefaultjpegencodeparam(bi);
param.setquality(1f, false);//不压缩图像
encoder.setjpegencodeparam(param);
try
{
encoder.encode(bi);
out.close();
}
catch (java.io.ioexception io)
{
system.out.println( "ioexception ");
}
[解决办法]
网页直接访问客户端摄像头的话需要客户端或者插件吧?
[解决办法]
学习一下!
[解决办法]
mark
[解决办法]
值得学习,帮顶
[解决办法]
关注
[解决办法]
关注
[解决办法]
用flash来作界面是理想选择.
[解决办法]
把.jar文件导入。下载了jmf后需要安装,安装后你的那个jmf目录下就会有一个lib文件夹里面有.jar文件,然后打开eclipse,右键选择你的工程-〉属性-〉java build path-> library-〉add external jars 找到你的jmf目录下lib的那个文件夹然后选中那些文件导入就ok了。
然后利用工具提供的导入文件帮助,一个一个导就OK了
[解决办法]
jsp不可能实现的,jsp是服务器端的,实现楼主的功能如果非要用java,可以用applet
[解决办法]
我们与前做过。是自学考试的报名系统。J2EE 平台。如 liu_an(从来不上网) 说的 需要 applet。J2EE 是在服务器运行的与你的客户端无关。建意你如果客户端是MS 的 用 ActiveX 会好一点。
[解决办法]
哎, jsp里就是能实现也是调服务器端的摄想头。
劝你换路子,考虑下flash com之类的吧, 只要客户装了flash就可以实现这个功能。
用java实现你的想法,不现实
[解决办法]
可能楼上有位的JMF才好用吧,用JAVA窗体可能好一些。WEB的就不用考虑了