|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
2003年中微软发布最新版本的ASP.netWebMatrix,对于我们喜欢用Asp.net来编程的朋友实在是个好消息,我也实实在在的将Asp.net更深入的研究了一下,以方便我以后更好的运用它,同时我也讲讲使用它的感受。数据没甚么好说的了,我把代码都贴出来,人人本人看吧!
webcam类的代码:
usingSystem;
usingSystem.Runtime.InteropServices;namespacewebcam
{
/**////
///avicap的择要申明。
///
publicclassshowVideo
{
//showVideocalls
[DllImport("avicap32.dll")]publicstaticexternIntPtrcapCreateCaptureWindowA(byte[]lpszWindowName,intdwStyle,intx,inty,intnWidth,intnHeight,IntPtrhWndParent,intnID);
[DllImport("avicap32.dll")]publicstaticexternboolcapGetDriverDescriptionA(shortwDriver,byte[]lpszName,intcbName,byte[]lpszVer,intcbVer);
[DllImport("User32.dll")]publicstaticexternboolSendMessage(IntPtrhWnd,intwMsg,boolwParam,intlParam);
[DllImport("User32.dll")]publicstaticexternboolSendMessage(IntPtrhWnd,intwMsg,shortwParam,intlParam);
[DllImport("User32.dll")]publicstaticexternboolSendMessage(IntPtrhWnd,intwMsg,shortwParam,FrameEventHandlerlParam);
[DllImport("User32.dll")]publicstaticexternboolSendMessage(IntPtrhWnd,intwMsg,intwParam,refBITMAPINFOlParam);
[DllImport("User32.dll")]publicstaticexternintSetWindowPos(IntPtrhWnd,inthWndInsertAfter,intx,inty,intcx,intcy,intwFlags);
[DllImport("avicap32.dll")]publicstaticexternintcapGetVideoFormat(IntPtrhWnd,IntPtrpsVideoFormat,intwSize);
//Constants
publicconstintWM_USER=0x400;
publicconstintWS_CHILD=0x40000000;
publicconstintWS_VISIBLE=0x10000000;
publicconstintSWP_NOMOVE=0x2;
publicconstintSWP_NOZORDER=0x4;
publicconstintWM_CAP_DRIVER_CONNECT=WM_USER+10;
publicconstintWM_CAP_DRIVER_DISCONNECT=WM_USER+11;
publicconstintWM_CAP_SET_CALLBACK_FRAME=WM_USER+5;
publicconstintWM_CAP_SET_PREVIEW=WM_USER+50;
publicconstintWM_CAP_SET_PREVIEWRATE=WM_USER+52;
publicconstintWM_CAP_SET_VIDEOFORMAT=WM_USER+45;
//Structures
[StructLayout(LayoutKind.Sequential)]publicstructVIDEOHDR
{
[MarshalAs(UnmanagedType.I4)]publicintlpData;
[MarshalAs(UnmanagedType.I4)]publicintdwBufferLength;
[MarshalAs(UnmanagedType.I4)]publicintdwBytesUsed;
[MarshalAs(UnmanagedType.I4)]publicintdwTimeCaptured;
[MarshalAs(UnmanagedType.I4)]publicintdwUser;
[MarshalAs(UnmanagedType.I4)]publicintdwFlags;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=4)]publicint[]dwReserved;
}
[StructLayout(LayoutKind.Sequential)]publicstructBITMAPINFOHEADER
{
[MarshalAs(UnmanagedType.I4)]publicInt32biSize;
[MarshalAs(UnmanagedType.I4)]publicInt32biWidth;
[MarshalAs(UnmanagedType.I4)]publicInt32biHeight;
[MarshalAs(UnmanagedType.I2)]publicshortbiPlanes;
[MarshalAs(UnmanagedType.I2)]publicshortbiBitCount;
[MarshalAs(UnmanagedType.I4)]publicInt32biCompression;
[MarshalAs(UnmanagedType.I4)]publicInt32biSizeImage;
[MarshalAs(UnmanagedType.I4)]publicInt32biXPelsPerMeter;
[MarshalAs(UnmanagedType.I4)]publicInt32biYPelsPerMeter;
[MarshalAs(UnmanagedType.I4)]publicInt32biClrUsed;
[MarshalAs(UnmanagedType.I4)]publicInt32biClrImportant;
}
[StructLayout(LayoutKind.Sequential)]publicstructBITMAPINFO
{
[MarshalAs(UnmanagedType.Struct,SizeConst=40)]publicBITMAPINFOHEADERbmiHeader;
[MarshalAs(UnmanagedType.ByValArray,SizeConst=1024)]publicInt32[]bmiColors;
}
publicdelegatevoidFrameEventHandler(IntPtrlwnd,IntPtrlpVHdr);
//Publicmethods
publicstaticobjectGetStructure(IntPtrptr,ValueTypestructure)
{
returnMarshal.PtrToStructure(ptr,structure.GetType());
}
publicstaticobjectGetStructure(intptr,ValueTypestructure)
{
returnGetStructure(newIntPtr(ptr),structure);
}
publicstaticvoidCopy(IntPtrptr,byte[]data)
{
Marshal.Copy(ptr,data,0,data.Length);
}
publicstaticvoidCopy(intptr,byte[]data)
{
Copy(newIntPtr(ptr),data);
}
publicstaticintSizeOf(objectstructure)
{
returnMarshal.SizeOf(structure);
}
}
//WebCameraClass
publicclassWebCamera
{
//Constructur
publicWebCamera(IntPtrhandle,intwidth,intheight)
{
mControlPtr=handle;
mWidth=width;
mHeight=height;
}
//delegateforframecallback
publicdelegatevoidRecievedFrameEventHandler(byte[]data);
publiceventRecievedFrameEventHandlerRecievedFrame;
privateIntPtrlwndC;//Holdstheunmanagedhandleofthecontrol
privateIntPtrmControlPtr;//Holdsthemanagedpointerofthecontrol
privateintmWidth;
privateintmHeight;
privateshowVideo.FrameEventHandlermFrameEventHandler;//Delegateinstancefortheframecallback-mustkeepalive!gcshouldNOTcollectit
//Closethewebcamera
publicvoidCloseWebcam()
{
this.capDriverDisconnect(this.lwndC);
}
//startthewebcamera
publicvoidStartWebCam()
{
byte[]lpszName=newbyte[100];
byte[]lpszVer=newbyte[100];
showVideo.capGetDriverDescriptionA(0,lpszName,100,lpszVer,100);
this.lwndC=showVideo.capCreateCaptureWindowA(lpszName,showVideo.WS_VISIBLE+showVideo.WS_CHILD,0,0,mWidth,mHeight,mControlPtr,0);
if(this.capDriverConnect(this.lwndC,0))
{
this.capPreviewRate(this.lwndC,66);
this.capPreview(this.lwndC,true);
showVideo.BITMAPINFObitmapinfo=newshowVideo.BITMAPINFO();
bitmapinfo.bmiHeader.biSize=showVideo.SizeOf(bitmapinfo.bmiHeader);
bitmapinfo.bmiHeader.biWidth=352;
bitmapinfo.bmiHeader.biHeight=288;
bitmapinfo.bmiHeader.biPlanes=1;
bitmapinfo.bmiHeader.biBitCount=24;
this.capSetVideoFormat(this.lwndC,refbitmapinfo,showVideo.SizeOf(bitmapinfo));
this.mFrameEventHandler=newshowVideo.FrameEventHandler(FrameCallBack);
this.capSetCallbackOnFrame(this.lwndC,this.mFrameEventHandler);
showVideo.SetWindowPos(this.lwndC,0,0,0,mWidth,mHeight,6);
}
}
//privatefunctions
privateboolcapDriverConnect(IntPtrlwnd,shorti)
{
returnshowVideo.SendMessage(lwnd,showVideo.WM_CAP_DRIVER_CONNECT,i,0);
}
privateboolcapDriverDisconnect(IntPtrlwnd)
{
returnshowVideo.SendMessage(lwnd,showVideo.WM_CAP_DRIVER_DISCONNECT,0,0);
}
privateboolcapPreview(IntPtrlwnd,boolf)
{returnshowVideo.SendMessage(lwnd,showVideo.WM_CAP_SET_PREVIEW,f,0);}
privateboolcapPreviewRate(IntPtrlwnd,shortwMS)
{
returnshowVideo.SendMessage(lwnd,showVideo.WM_CAP_SET_PREVIEWRATE,wMS,0);
}
privateboolcapSetCallbackOnFrame(IntPtrlwnd,showVideo.FrameEventHandlerlpProc)
{
returnshowVideo.SendMessage(lwnd,showVideo.WM_CAP_SET_CALLBACK_FRAME,0,lpProc);
}
privateboolcapSetVideoFormat(IntPtrhCapWnd,refshowVideo.BITMAPINFOBmpFormat,intCapFormatSize)
{
returnshowVideo.SendMessage(hCapWnd,showVideo.WM_CAP_SET_VIDEOFORMAT,CapFormatSize,refBmpFormat);
}
privatevoidFrameCallBack(IntPtrlwnd,IntPtrlpVHdr)
{
showVideo.VIDEOHDRvideoHeader=newshowVideo.VIDEOHDR();
byte[]VideoData;
videoHeader=(showVideo.VIDEOHDR)showVideo.GetStructure(lpVHdr,videoHeader);
VideoData=newbyte[videoHeader.dwBytesUsed];
showVideo.Copy(videoHeader.lpData,VideoData);
if(this.RecievedFrame!=null)
this.RecievedFrame(VideoData);
}
}
}
上面是完成的代码
usingSystem;
usingSystem.Drawing;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Windows.Forms;
usingSystem.Data;
usingwebcam;
namespacewebcam
{
/**////
///Form1的择要申明。
///
publicclassForm1:System.Windows.Forms.Form
{
privateSystem.Windows.Forms.PanelpanelPreview;
privateSystem.Windows.Forms.Buttonb_play;
privateSystem.Windows.Forms.Buttonb_stop;
/**////
///必须的计划器变量。
///
privateSystem.ComponentModel.Containercomponents=null;
WebCamerawc;
publicForm1()
{
//
//Windows窗体计划器撑持所必须的
//
InitializeComponent();
//
//TODO:在InitializeComponent挪用后增加任何机关函数代码
//
}
/**////
///清算一切正在利用的资本。
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
Windows窗体计划器天生的代码#regionWindows窗体计划器天生的代码
/**////
///计划器撑持所需的办法-不要利用代码编纂器修正
///此办法的内容。
///
privatevoidInitializeComponent()
{
this.b_play=newSystem.Windows.Forms.Button();
this.panelPreview=newSystem.Windows.Forms.Panel();
this.b_stop=newSystem.Windows.Forms.Button();
this.SuspendLayout();
//
//b_play
//
this.b_play.Location=newSystem.Drawing.Point(280,368);
this.b_play.Name="b_play";
this.b_play.TabIndex=0;
this.b_play.Text="&Play";
this.b_play.Click+=newSystem.EventHandler(this.button1_Click);
//
//panelPreview
//
this.panelPreview.Location=newSystem.Drawing.Point(8,8);
this.panelPreview.Name="panelPreview";
this.panelPreview.Size=newSystem.Drawing.Size(344,272);
this.panelPreview.TabIndex=1;
//
//b_stop
//
this.b_stop.Enabled=false;
this.b_stop.Location=newSystem.Drawing.Point(360,368);
this.b_stop.Name="b_stop";
this.b_stop.TabIndex=2;
this.b_stop.Text="&Stop";
this.b_stop.Click+=newSystem.EventHandler(this.b_stop_Click);
//
//Form1
//
this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);
this.ClientSize=newSystem.Drawing.Size(464,413);
this.Controls.Add(this.b_stop);
this.Controls.Add(this.panelPreview);
this.Controls.Add(this.b_play);
this.MaximizeBox=false;
this.MinimizeBox=false;
this.Name="Form1";
this.Text="GoodViewtestWebCamera";
this.Load+=newSystem.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**////
///使用程序的主出口点。
///
[STAThread]
staticvoidMain()
{
Application.Run(newForm1());
}
privatevoidForm1_Load(objectsender,System.EventArgse)
{
b_play.Enabled=false;
b_stop.Enabled=true;
panelPreview.Size=newSize(330,330);
wc=newWebCamera(panelPreview.Handle,panelPreview.Width,panelPreview.Height);
wc.StartWebCam();
}
privatevoidbutton1_Click(objectsender,System.EventArgse)
{
b_play.Enabled=false;
b_stop.Enabled=true;
panelPreview.Size=newSize(330,330);
wc=newWebCamera(panelPreview.Handle,panelPreview.Width,panelPreview.Height);
wc.StartWebCam();
}
privatevoidb_stop_Click(objectsender,System.EventArgse)
{
b_play.Enabled=true;
b_stop.Enabled=false;
wc.CloseWebcam();
}
}
}
你所列的那些其实差不多都可以称为应用服务器(servlet应该说是一种语言更合适)java是开放的,相同的工具就会有很多公司在做,加上java已经发展了很多年了,因此这些工具就很多了。他们很多都是类似的。 |
|