下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 摄像头程序

摄像头程序.doc

摄像头程序

嫒倪媍是措
2017-12-26 0人阅读 举报 0 0 暂无简介

简介:本文档为《摄像头程序doc》,可适用于IT/计算机领域

摄像头程序usingSystemusingSystemRuntimeInteropServicesusingSystemCollectionsGenericusingSystemComponentModelusingSystemDatausingSystemDrawingusingSystemDrawingImagingusingSystemTextusingSystemWindowsFormsnamespaceWindowsApplication{publicpartialclassForm:Form{publicForm(){InitializeComponent()}publicclassPick{privateconstintWMUSER=xprivateconstintWSCHILD=xprivateconstintWSVISIBLE=xprivateconstintWMCAPSTART=WMUSERprivateconstintWMCAPSTOP=WMCAPSTARTprivateconstintWMCAPDRIVERCONNECT=WMCAPSTARTprivateconstintWMCAPDRIVERDISCONNECT=WMCAPSTARTprivateconstintWMCAPSAVEDIB=WMCAPSTARTprivateconstintWMCAPGRABFRAME=WMCAPSTARTprivateconstintWMCAPSEQUENCE=WMCAPSTARTprivateconstintWMCAPFILESETCAPTUREFILEA=WMCAPSTARTprivateconstintWMCAPSEQUENCENOFILE=WMCAPSTARTprivateconstintWMCAPSETOVERLAY=WMCAPSTARTprivateconstintWMCAPSETPREVIEW=WMCAPSTARTprivateconstintWMCAPSETCALLBACKVIDEOSTREAM=WMCAPSTARTprivateconstintWMCAPSETCALLBACKERROR=WMCAPSTARTprivateconstintWMCAPSETCALLBACKSTATUSA=WMCAPSTARTprivateconstintWMCAPSETCALLBACKFRAME=WMCAPSTARTprivateconstintWMCAPSETSCALE=WMCAPSTARTprivateconstintWMCAPSETPREVIEWRATE=WMCAPSTARTpublicstaticintWMCAPDLGVIDEOSOURCE=(WMCAPSTART)选择摄像头privateIntPtrhWndCprivateboolbStat=falseprivateIntPtrmControlPtrprivateintmWidthprivateintmHeightprivateintmLeftprivateintmTop<summary>初始化摄像头<summary><paramname="handle">控件的句柄<param><paramname="left">开始显示的左边距<param><paramname="top">开始显示的上边距<param><paramname="width">要显示的宽度<param><paramname="height">要显示的长度<param>publicPick(IntPtrhandle,intleft,inttop,intwidth,intheight){mControlPtr=handlemWidth=widthmHeight=heightmLeft=leftmTop=top}DllImport("avicapdll")privatestaticexternIntPtrcapCreateCaptureWindowA(bytelpszWindowName,intdwStyle,intx,inty,intnWidth,intnHeight,IntPtrhWndParent,intnID)DllImport("avicapdll")privatestaticexternintcapGetVideoFormat(IntPtrhWnd,IntPtrpsVideoFormat,intwSize)DllImport("Userdll")privatestaticexternboolSendMessage(IntPtrhWnd,intwMsg,intwParam,intlParam)<summary>开始显示图像<summary>publicvoidStart(){if(bStat)returnbStat=truebytelpszName=newbytehWndC=capCreateCaptureWindowA(lpszName,WSCHILD|WSVISIBLE,mLeft,mTop,mWidth,mHeight,mControlPtr,)if(hWndCToInt()!=){SendMessage(hWndC,WMCAPSETCALLBACKVIDEOSTREAM,,)SendMessage(hWndC,WMCAPSETCALLBACKERROR,,)SendMessage(hWndC,WMCAPSETCALLBACKSTATUSA,,)SendMessage(hWndC,WMCAPDRIVERCONNECT,,)SendMessage(hWndC,WMCAPSETSCALE,,)SendMessage(hWndC,WMCAPSETPREVIEWRATE,,)SendMessage(hWndC,WMCAPSETOVERLAY,,)SendMessage(hWndC,WMCAPSETPREVIEW,,)}return}<summary>停止显示<summary>publicvoidStop(){SendMessage(hWndC,WMCAPDRIVERDISCONNECT,,)bStat=false}<summary>抓图<summary><paramname="path">要保存bmp文件的路径<param>publicvoidGrabImage(stringpath){IntPtrhBmp=MarshalStringToHGlobalAnsi(path)SendMessage(hWndC,WMCAPSAVEDIB,,hBmpToInt())}<summary>录像<summary><paramname="path">要保存avi文件的路径<param>publicvoidKinescope(stringpath){IntPtrhBmp=MarshalStringToHGlobalAnsi(path)SendMessage(hWndC,WMCAPFILESETCAPTUREFILEA,,hBmpToInt())SendMessage(hWndC,WMCAPSEQUENCE,,)}<summary>停止录像<summary>publicvoidStopKinescope(){SendMessage(hWndC,WMCAPSTOP,,)}<summary><summary>publicvoidSetShow(){SendMessage(hWndC,WMCAPDLGVIDEOSOURCE,,)}}privatevoidbuttonClick(objectsender,EventArgse){try{SaveFileDialogSaveFileDialog=newSaveFileDialog()SaveFileDialogFilter="bmpfiles(*bmp)|*bmp|jpgfiles(*jpg)|*jpg|Allfiles(**)|**"SaveFileDialogFilterIndex=默认图片保存格式JPGSaveFileDialogRestoreDirectory=trueSaveFileDialogFileName="Pic"默认图片保存名称Picif(SaveFileDialogShowDialog()==DialogResultOK){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkGrabImage(SaveFileDialogFileName)}}catch{}}privatevoidbuttonClick(objectsender,EventArgse){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkStart()}privatevoidbuttonClick(objectsender,EventArgse){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkStop()}privatevoidbuttonClick(objectsender,EventArgse){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkGrabImage("c:bmp")}privatevoidbuttonClick(objectsender,EventArgse){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkKinescope("c:avi")}privatevoidbuttonClick(objectsender,EventArgse){FormPickpk=newPick(Handle,panelLeft,panelTop,panelWidth,panelHeight)pkStopKinescope()}获取摄像头的代码usingSystemusingSystemDrawingusingSystemCollectionsusingSystemComponentModelusingSystemWindowsFormsusingSystemDatausingSystemRuntimeInteropServicesusingSystemDrawingImagingnamespaceCapTureMovie{<summary>Form的摘要说明。<summary>publicclassForm:SystemWindowsFormsForm{privateSystemWindowsFormsButtonBtnCapTureprivateSystemWindowsFormsPanelpanelVedioprivateinthHwndprivateSystemWindowsFormsButtonBtnStopprivateSystemWindowsFormsLabelLbSysMsgprivateSystemWindowsFormsButtonbuttonpublicstructvideohdrtag{publicbytelpDatapublicintdwBufferLengthpublicintdwBytesUsedpublicintdwTimeCapturedpublicintdwUserpublicintdwFlagspublicintdwReserved}publicdelegateboolCallBack(inthwnd,intlParam)<summary>必需的设计器变量。<summary>privateSystemComponentModelContainercomponents=DllImport("avicapdll",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternintcapCreateCaptureWindowA(MarshalAs(UnmanagedTypeVBByRefStr)refstringlpszWindowName,intdwStyle,intx,inty,intnWidth,shortnHeight,inthWndParent,intnID)DllImport("avicapdll",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternboolcapGetDriverDescriptionA(shortwDriver,MarshalAs(UnmanagedTypeVBByRefStr)refstringlpszName,intcbName,MarshalAs(UnmanagedTypeVBByRefStr)refstringlpszVer,intcbVer)DllImport("user",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternboolDestroyWindow(inthndw)DllImport("user",EntryPoint="SendMessageA",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternintSendMessage(inthwnd,intwMsg,intwParam,MarshalAs(UnmanagedTypeAsAny)objectlParam)DllImport("user",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternintSetWindowPos(inthwnd,inthWndInsertAfter,intx,inty,intcx,intcy,intwFlags)DllImport("vfwdll")publicstaticexternstringcapVideoStreamCallback(inthwnd,videohdrtagvideohdrtag)DllImport("vicapdll",CharSet=CharSetAnsi,SetLastError=true,ExactSpelling=true)publicstaticexternboolcapSetCallbackOnFrame(inthwnd,strings)publicForm(){Windows窗体设计器支持所必需的InitializeComponent()TODO:在InitializeComponent调用后添加任何构造函数代码}<summary>清理所有正在使用的资源。<summary>protectedoverridevoidDispose(booldisposing){if(disposing){if(components!=){componentsDispose()}}baseDispose(disposing)}#regionWindows窗体设计器生成的代码<summary>设计器支持所需的方法不要使用代码编辑器修改此方法的内容。<summary>privatevoidInitializeComponent(){SystemResourcesResourceManagerresources=newSystemResourcesResourceManager(typeof(Form))thispanelVedio=newSystemWindowsFormsPanel()thisBtnCapTure=newSystemWindowsFormsButton()thisBtnStop=newSystemWindowsFormsButton()thisLbSysMsg=newSystemWindowsFormsLabel()thisbutton=newSystemWindowsFormsButton()thisSuspendLayout()panelVediothispanelVedioBackgroundImage=((SystemDrawingImage)(resourcesGetObject("panelVedioBackgroundImage")))thispanelVedioBorderStyle=SystemWindowsFormsBorderStyleFixedDthispanelVedioLocation=newSystemDrawingPoint(,)thispanelVedioName="panelVedio"thispanelVedioSize=newSystemDrawingSize(,)thispanelVedioTabIndex=BtnCapTurethisBtnCapTureLocation=newSystemDrawingPoint(,)thisBtnCapTureName="BtnCapTure"thisBtnCapTureTabIndex=thisBtnCapTureText="图象采集"thisBtnCapTureClick=newSystemEventHandler(thisBtnCapTureClick)BtnStopthisBtnStopEnabled=falsethisBtnStopLocation=newSystemDrawingPoint(,)thisBtnStopName="BtnStop"thisBtnStopTabIndex=thisBtnStopText="停止采集"thisBtnStopClick=newSystemEventHandler(thisBtnStopClick)LbSysMsgthisLbSysMsgLocation=newSystemDrawingPoint(,)thisLbSysMsgName="LbSysMsg"thisLbSysMsgSize=newSystemDrawingSize(,)thisLbSysMsgTabIndex=buttonthisbuttonLocation=newSystemDrawingPoint(,)thisbuttonName="button"thisbuttonTabIndex=thisbuttonText="button"thisbuttonClick=newSystemEventHandler(thisbuttonClick)FormthisAutoScaleBaseSize=newSystemDrawingSize(,)thisClientSize=newSystemDrawingSize(,)thisControlsAdd(thisbutton)thisControlsAdd(thisLbSysMsg)thisControlsAdd(thisBtnCapTure)thisControlsAdd(thispanelVedio)thisControlsAdd(thisBtnStop)thisName="Form"thisText="Form"thisResumeLayout(false)}#endregion<summary>应用程序的主入口点。<summary>STAThreadstaticvoidMain(){ApplicationRun(newForm())}privatevoidBtnCapTureClick(objectsender,SystemEventArgse){thisOpenCapture()}privatevoidOpenCapture(){intintWidth=thispanelVedioWidthintintHeight=thispanelVedioHeightintintDevice=stringrefDevice=intDeviceToString()hHwnd=FormcapCreateCaptureWindowA(refrefDevice,,,,,,thispanelVedioHandleToInt(),)thisLbSysMsgText=""thisLbSysMsgText="驱动:"refDeviceif(FormSendMessage(hHwnd,xa,intDevice,)>){FormSendMessage(thishHwnd,x,,)FormSendMessage(thishHwnd,x,x,)FormSendMessage(thishHwnd,x,,)FormSetWindowPos(thishHwnd,,,,intWidth,intHeight,)thisBtnCapTureEnabled=falsethisBtnStopEnabled=true}else{FormDestroyWindow(thishHwnd)thisBtnCapTureEnabled=falsethisBtnStopEnabled=true}}privatevoidBtnStopClick(objectsender,SystemEventArgse){FormSendMessage(thishHwnd,xb,,)FormDestroyWindow(thishHwnd)thisBtnCapTureEnabled=truethisBtnStopEnabled=false}privatevoidbuttonClick(objectsender,SystemEventArgse){try{FormSendMessage(thishHwnd,xe,,)IDataObjectobj=ClipboardGetDataObject()if(objGetDataPresent(typeof(Bitmap))){Imageimage=(Image)objGetData(typeof(Bitmap))thispanelVedioImage=imagethisClosePreviewWindow()SaveFileDialogSaveFileDialog=newSaveFileDialog()if(SaveFileDialogShowDialog()==DialogResultOK){imageSave(SaveFileDialogFileName,ImageFormatBmp)}}}catch{}}}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/18

摄像头程序

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利