给你看这个 ,希望对你有帮助 。http://www.cnblogs.com/xidongs/archive/2009/07/14/1523617.html
解决方案 »
- List<double>,找到其最大值的索引!
- 嵌套实体的绑定
- gridview每行插入一条线
- 水晶报表各列可否按照用户要求动态显示所需列
- 以编程方式创建ASCX实例后,F5可以正常运行,编译也同过,就是不能Publish?!VS2005是不是有毛病?
- 求一打印代码,ASP。NET的,如果单击一下打印整张页面!最好是客户端的控件打印!
- 圣诞快乐,请教利用datagrid如何向数据库插入数据?
- 分享:技术文章阅读排行榜
- 为了感谢大家的支持, 发布我的4个控件(源码), 请大家请教请教
- 请问:DataGrid中如何添加“取消”按钮的客户端事件?
- datagrid 备注的浮动显示
- 如何将选择的CheckBoxList中的数据通过添加按钮添加到ListBox中
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;namespace CapAvi
{
/// <summary>
/// 一个控制摄像头的类
/// </summary>
public class CamCap
{
private const int WM_USER = 0x400;
private const int WS_CHILD = 0x40000000;
private const int WS_VISIBLE = 0x10000000;
private const int WM_CAP_START = WM_USER;
private const int WM_CAP_STOP = WM_CAP_START + 68;
private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;
private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;
private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;
private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;
private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;
private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;
private const int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;
private const int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;
private const int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;
private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;
private const int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;
private const int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;
private const int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;
private const int WM_CAP_SET_SCALE=WM_CAP_START+ 53;
private const int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;
private IntPtr hWndC;
private bool bStat = false; private IntPtr mControlPtr;
private int mWidth;
private int mHeight;
private int mLeft;
private int mTop; /// <summary>
/// 初始化摄像头
/// </summary>
/// <param name="handle">控件的句柄</param>
/// <param name="left">开始显示的左边距</param>
/// <param name="top">开始显示的上边距</param>
/// <param name="width">要显示的宽度</param>
/// <param name="height">要显示的长度</param>
public CamCap(IntPtr handle, int left, int top, int width,int height)
{
mControlPtr = handle;
mWidth = width;
mHeight = height;
mLeft = left;
mTop = top;
} [DllImport("avicap32.dll")]
private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
[DllImport("avicap32.dll")]
private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam); /// <summary>
/// 开始显示图像
/// </summary>
public void Start()
{
if (bStat)
return; bStat = true;
byte[] lpszName = new byte[100]; hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0); if (hWndC.ToInt32() != 0)
{
SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
} return; } /// <summary>
/// 停止显示
/// </summary>
public void Stop()
{
SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
bStat = false;
} /// <summary>
/// 抓图
/// </summary>
/// <param name="path">要保存bmp文件的路径</param>
public void GrabImage(string path)
{ IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC,WM_CAP_SAVEDIB,0,hBmp.ToInt64()); } /// <summary>
/// 录像
/// </summary>
/// <param name="path">要保存avi文件的路径</param>
public void Kinescope(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
SendMessage(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,hBmp.ToInt64());
SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
} /// <summary>
/// 停止录像
/// </summary>
public void StopKinescope()
{
SendMessage(hWndC, WM_CAP_STOP, 0, 0);
} }
}
单纯的web我想没这么强大
{
//5个传入参数
private IntPtr myHand;
private int myWidth;
private short myHeight;
private int myLeft;
private int myTop;
//调用avicap32.dll
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; }
[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);
//自定义参数:
private int hHwnd;
//构造函数
public video(IntPtr myPtr, int left, int top, int width, short height)
{
myHand = myPtr;
myLeft = left;
myTop = top;
myWidth = width;
myHeight = height;
//
// TODO: 在此处添加构造函数逻辑
//
} //打开视频:
public void opVideo()
{
int intDevice = 0;
string refDevice = intDevice.ToString();
hHwnd = capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, myHand.ToInt32(), 0);
if (SendMessage(hHwnd, 0x40a, intDevice, 0) > 0)
{
SendMessage(this.hHwnd, 0x435, -1, 0);
SendMessage(this.hHwnd, 0x434, 0x42, 0);
SendMessage(this.hHwnd, 0x432, -1, 0);
SetWindowPos(this.hHwnd, 1, 0, 0, myWidth, Convert.ToInt32(myHeight), 6);
}
else
{
DestroyWindow(this.hHwnd);
}
}
//停止视频
public void CloVideo()
{
SendMessage(this.hHwnd, 0x40b, 0, 0);
DestroyWindow(this.hHwnd);
}
//捕获视频
public Image CatchVideo()
{
SendMessage(this.hHwnd, 0x41e, 0, 0);
IDataObject obj1 = Clipboard.GetDataObject();
Image getIma = null;
if (obj1.GetDataPresent(typeof(Bitmap)))
{
Image image1 = (Image)obj1.GetData(typeof(Bitmap));
getIma = image1;
}
return getIma;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace 摄像头
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} const short WM_CAP = 1024;
const int WM_CAP_DRIVER_CONNECT = WM_CAP + 10;
const int WM_CAP_DRIVER_DISCONNECT = WM_CAP + 11;
const int WM_CAP_EDIT_COPY = WM_CAP + 30;
const int WM_CAP_SET_PREVIEW = WM_CAP + 50;
const int WM_CAP_SET_PREVIEWRATE = WM_CAP + 52;
const int WM_CAP_SET_SCALE = WM_CAP + 53;
const int WS_CHILD = 1073741824;
const int WS_VISIBLE = 268435456;
const short SWP_NOMOVE = 2;
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 4;
const short HWND_BOTTOM = 1;
int iDevice = 0;
int hHwnd;
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)]
object lParam);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowPos")]
static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[System.Runtime.InteropServices.DllImport("user32")]
static extern bool DestroyWindow(int hndw);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer);
private void OpenPreviewWindow()
{
int iHeight = 320;
int iWidth = 200;
//
// Open Preview window in picturebox //打开预览窗口的PictureBox
//
hHwnd = capCreateCaptureWindowA(iDevice.ToString(), (WS_VISIBLE | WS_CHILD), 0, 0, 640, 480, picCapture.Handle.ToInt32(), 0);
//
// Connect to device 连接到设备
//
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) == 1)
{
//
// Set the preview scale 设置预览规模
//
SendMessage(hHwnd, WM_CAP_SET_SCALE, 1, 0);
//
// Set the preview rate in milliseconds 以毫秒为单位设置预览率
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
//
// Start previewing the image from the camera 从相机启动预览图像
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
//
// Resize window to fit in picturebox 调整窗口大小以适应在PictureBox中
//
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth, iHeight, (SWP_NOMOVE | SWP_NOZORDER));
}
else
{
//
// Error connecting to device close window 错误连接到设备关闭窗口
//
DestroyWindow(hHwnd);
}
}
private void ClosePreviewWindow()
{
//
// Disconnect from device 断开设备
//
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0);
//
// close window 关闭窗口
//
DestroyWindow(hHwnd);
}
private void button1_Click(object sender, EventArgs e)
{
iDevice = int.Parse("4");
OpenPreviewWindow();
} private void button2_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
} private void Form1_Load(object sender, EventArgs e)
{ }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YL;
namespace 摄像头
{
public partial class Form2 : Form
{
video v;
public Form2()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog sa = new SaveFileDialog();
sa.Filter = "保存(*.bmp)|*.bmp";
sa.FilterIndex = 2;
sa.RestoreDirectory = true;
if (DialogResult.OK == sa.ShowDialog())
{
Image im = v.CatchVideo();
Bitmap bit = new Bitmap(im);
bit.Save(sa.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
} } private void button2_Click(object sender, EventArgs e)
{
v = new video(pictureBox1.Handle, 250, 250, 429, 310);
v.opVideo();
} private void button3_Click(object sender, EventArgs e)
{
v.CloVideo();
}
}
}
2、fms(媒体服务器)方式,网上这方面的资料比较多。资料