|
< >我程式中需要控制CCD來做照相的功能,我是想使用Picture這個元件來做預覽的功能以及顯示我所擷取到的影像,目前是可以達到我要擷取影像的功能,但卻無法做到能事前預覽的動作,請問板上的高手們,下方是我的程式碼!那我該做什麼修正呢?!才可以達成我想要預覽的目的呢?!</P>
< >#include <windows.h>
#include <utility.h>
#include <vfw.h>
#include <ansi_c.h></P>
< >#include <cvirte.h>
#include <userint.h>
#include "test3.h"</P>
<P>static int panelHandle;</P>
<P>static int winHandle ;</P>
<P>char PathName[MAX_PATHNAME_LEN] ;</P>
<P>HWND hCapWnd;
BITMAPINFO bmi;
CAPTUREPARMS CapParms ;</P>
<P>int width , height ;</P>
<P>int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "test3.uir", PANEL)) < 0)
return -1;</P>
<P> width = 352 ;
height = 288 ;
winHandle = GetCVIWindowHandle() ;
hCapWnd = capCreateCaptureWindow("Capture Window", WS_CHILD | WS_VISIBLE , 0 , 0 , width , height, (HWND)winHandle , PANEL_PICTURE); //設定CaptureWindows
capDriverConnect(hCapWnd, 0) ;//與驅動程式連結
</P>
<P> capGetVideoFormat(hCapWnd, &bmi, sizeof(BITMAPINFO));
bmi.bmiHeader.biWidth=width;
bmi.bmiHeader.biHeight=height;
SetWindowPos (hCapWnd, 0, 0, 0, bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,0);
SetCtrlAttribute (panelHandle , PANEL_PICTURE , ATTR_HEIGHT , bmi.bmiHeader.biHeight) ;
SetCtrlAttribute (panelHandle , PANEL_PICTURE , ATTR_WIDTH , bmi.bmiHeader.biWidth) ;
capSetVideoFormat(hCapWnd, &bmi, sizeof(BITMAPINFO)) ;
capCaptureGetSetup(hCapWnd , &CapParms , sizeof(CAPTUREPARMS)) ;
CapParms.dwRequestMicroSecPerFrame = 40000;
CapParms.fLimitEnabled = FALSE;
CapParms.fCaptureAudio = FALSE; // NO Audio
CapParms.fMCIControl = FALSE;
CapParms.fYield = TRUE;
CapParms.vKeyAbort = VK_ESCAPE;
CapParms.fAbortLeftMouse = FALSE;
CapParms.fAbortRightMouse = FALSE; </P>
<P> capCaptureSetSetup(hCapWnd , &CapParms , sizeof(CAPTUREPARMS)) ;
capDlgVideoCompression(hCapWnd);
capOverlay(hCapWnd, TRUE); //使用hardware overlay使video input directly into framebuffer,使不用CPU resources.
capPreview(hCapWnd,TRUE); //抓取影像出現在視窗中
capPreviewScale(hCapWnd,TRUE); //使影像延伸到所設定的視窗大小
capPreviewRate(hCapWnd, 1000/30); //每秒影像變化張數</P>
<P> DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;</P>
<P>}</P>
<P>int CVICALLBACK GetImageFun (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int i ;
char tmp[20] ;
int year , mon , day , hour , min , sec ;
char FileName[MAX_PATHNAME_LEN] , SaveFilePathName[MAX_PATHNAME_LEN] ;
switch (event)
{
case EVENT_COMMIT:
GetSystemDate (&mon , &day , &year) ;
GetSystemTime (&hour , &min , &sec) ;
sprintf (FileName , "%d%d%d%d%d%d.bmp" , year , mon , day , hour , min , sec) ;
MakePathname (PathName , FileName , SaveFilePathName) ;
capGrabFrame(hCapWnd); //從CCD中抓取單格影像,但CCD的Preview和Overlay將停止
capFileSaveDIB(hCapWnd,SaveFilePathName); //存成bmp檔
DisplayImageFile (panelHandle , PANEL_PICTURE , SaveFilePathName) ;
break;
}
return 0;
}</P>[em06][em06][em06][em06][em06][em06][em06][em06][em06][em06][em06][em06][em06] |
|