線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1899
推到 Plurk!
推到 Facebook!

請問這篇視訊擷取的程式 Timer 是從哪裡觸發的呢??

答題得分者是:ikk
istillloving
高階會員


發表:33
回覆:182
積分:183
註冊:2008-10-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-02-14 00:47:12 IP:220.129.xxx.xxx 訂閱
各位大大好:




我有照板上資源改了一下視訊擷取的程式

但是看來看去看不出哪裡有呼叫到這個Timer

[code cpp]
void __fastcall TForm1::Timer(TObject *Sender)
[/code]

還是這是哪一種宣告 不是使用元件的呢??

這跟一般Timer的宣告方式 好像不太一樣 找不到 到底哪裡有宣告是否要啟動等等的

[code cpp]
Timer1->Interval=1000;
//一般宣告
Timer1->Enabled=true;
[/code]

而且如果把

[code cpp]
void __fastcall TForm1::Timer(TObject *Sender)
[/code]

的內容改寫到一般的Timer元件上的話 畫面會呈現綠色而且一直閃爍

這到底是什麼原因呢?? 請各位賜教了~!!

以下附上程式碼 和 檔案


[code cpp]
//---------------------------------------------------------------------------
#include
#include
#include
#pragma hdrstop
#include <math.h><br />#include "Unit1.h"
#include
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

long color;

const int w=384,h=288;

int i,j,k,l;

Byte *ptra=new Byte[w],*ptr=new Byte[w];

RGBQUAD *PRGB=new RGBQUAD[w*h];
TMemoryStream *stream = new TMemoryStream;

double *buffg;

HWND vc1,hCapWnd,hwndCapture;
LPVIDEOHDR VideoStr; //宣告圖片資料
LRESULT CALLBACK FrameCallBack(HWND,Longint); //宣告callbackonframe函式

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{


buffg = new double[w*h];

BitmapA = new Graphics::TBitmap();

BitmapB = new Graphics::TBitmap();

BitmapE = new Graphics::TBitmap();

DoubleBuffered=true;
}
/*---------------------------------------------------------------------------

LRESULT CALLBACK FrameCallBack( HWND hwnd, Longint lpvhdr )
{

static BITMAPINFOHEADER BitmapHead;
static BITMAPINFO BitmapInfo;
static BITMAPFILEHEADER BitmapFileHead;

CAPSTATUS status;
int BIHsize, byte;
Byte *ptr;

// 取得圖片資料
VideoStr=LPVIDEOHDR(lpvhdr);
// 取得CAP訊息
capGetStatus( hCapWnd, &status, sizeof(status) ) ;
// 取得圖片格式容量大小
BIHsize=capGetVideoFormatSize( hCapWnd );
// 取得圖片格式 代入 bitmapinfohead 內
capGetVideoFormat( hCapWnd, &BitmapHead, BIHsize);
// 設定 BITMAPINFO
BitmapInfo.bmiHeader=BitmapHead;

stream->Size=sizeof(BitmapFileHead) sizeof(BitmapHead)-2 BitmapHead.biSizeImage;//減2

// 設定 BITMAPFILEHEAD
BitmapFileHead.bfType=0x4D42; // 總是 BM
BitmapFileHead.bfSize=stream->Size; //該圖檔總大小

BitmapFileHead.bfReserved1=(WORD)0;
BitmapFileHead.bfReserved2=(WORD)0;
BitmapFileHead.bfOffBits=sizeof(BitmapFileHead)-2 sizeof(BitmapHead); // 偏移至imagedata大小//減2

// 將資料存入 memorystream
stream->Position=0;
stream->WriteBuffer( &BitmapFileHead.bfType, sizeof(BitmapFileHead.bfType) );
stream->WriteBuffer( &BitmapFileHead.bfSize, sizeof(BitmapFileHead.bfSize) );
stream->WriteBuffer( &BitmapFileHead.bfReserved1, sizeof(BitmapFileHead.bfReserved1) );
stream->WriteBuffer( &BitmapFileHead.bfReserved2, sizeof(BitmapFileHead.bfReserved2) );
stream->WriteBuffer( &BitmapFileHead.bfOffBits, sizeof(BitmapFileHead.bfOffBits) );
stream->WriteBuffer( &BitmapInfo, sizeof(BitmapInfo) );

(void*)ptr=stream->Memory;
ptr = BitmapFileHead.bfOffBits;
Move( VideoStr->lpData, ptr, BitmapHead.biSizeImage);
// 存入完成
stream->Position=0;



//delete( stream );
capSetCallbackOnFrame (hCapWnd, NULL); // 停止callbackonframe
return(0);
}
//---------------------------------------------------------------------------*/
void __fastcall TForm1::Timer(TObject *Sender)
{
hCapWnd=capCreateCaptureWindow ( "Capture Window", WS_CHILD | WS_VISIBLE ,0,0,w,h,Panel1->Handle,0);//設定 CaptureWindows
capDriverConnect(hCapWnd,0);//呼叫視訊裝置 0 是編號
capOverlay(hCapWnd,true);
capPreview(hCapWnd,true);
capPreviewScale(hCapWnd,true);
capPreviewRate(hCapWnd,1000/30);//擷取影像延遲時間
Form1->Panel1->Height=h;
Form1->Panel1->Width=w;
Form1->Image1->Height=h;
Form1->Image1->Width=w;
Form1->Image2->Height=h;
Form1->Image2->Width=w;

Form1->Image1->Left=Form1->Panel1->Left;
Form1->Image1->Top=Form1->Panel1->Top Form1->Panel1->Height 10;
Form1->Image2->Left=Form1->Panel1->Left Form1->Panel1->Width 10;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
//capDlgVideoFormat(hCapWnd);
//capSetCallbackOnFrame (hCapWnd, &FrameCallBack);


Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->Width = Panel1->Width;
bmp->Height = Panel1->Height;
TCanvas *pCanvas = new TCanvas;
HDC hDC=GetDC(Panel1->Handle);
pCanvas->Handle=hDC;
pCanvas->Pen->Color = clBlue;
pCanvas->Pen->Width = 5;
pCanvas->Pen->Mode = pmCopy;
pCanvas->Pen->Style = psSolid;
pCanvas->Brush->Color = Color;
pCanvas->Brush->Style = bsClear;
pCanvas->Rectangle(0,0,50,50);
bmp->Canvas->CopyRect(Panel1->ClientRect,
pCanvas,
Panel1->ClientRect);

for(j=0;j {
for(i=0;i {
color=bmp->Canvas->Pixels[i][j];
(PRGB)[i j*w].rgbRed =GetRValue(color);
(PRGB)[i j*w].rgbGreen =GetGValue(color);
(PRGB)[i j*w].rgbBlue =GetBValue(color);
buffg[i w*j]=(double)(0.299*(PRGB)[i j*w].rgbRed 0.587*(PRGB)[i j*w].rgbGreen 0.114*(PRGB)[i j*w].rgbBlue 0.5);
}

}
Image2->Picture->Bitmap = bmp;
//bmp->SaveToFile("panel.bmp");
ReleaseDC(Panel1->Handle , hDC);
delete pCanvas;
delete bmp;


}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Timer1->Interval=1000;
Timer1->Enabled=true;

}
//---------------------------------------------------------------------------








[/code]
------
恩...
附加檔案:4995a41012542_Webcam.rar
編輯記錄
istillloving 重新編輯於 2009-02-14 00:49:23, 註解 無‧
ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-02-16 10:17:20 IP:163.28.xxx.xxx 訂閱
他放在Form1->OnCreate Event
打開 Object->Inspector的Events tab, 即可看到....
------
FPGA驗證, FPGA開發平台, http://smims.com
istillloving
高階會員


發表:33
回覆:182
積分:183
註冊:2008-10-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-02-16 23:09:01 IP:218.169.xxx.xxx 訂閱
非常感謝您 解答我的疑問......新手上路中
可否有延伸問題
就是程式中的

void __fastcall TForm1::Timer(TObject *Sender){...}


算是自己宣告在 Unit1.h 內 對吧 因為找不到Timer這個元件呢
那這樣應該也沒有繼承到TTimer的屬性


在程式執行時使用

[code cpp]
Form1->OnCreate
[/code]


呼叫一次 void __fastcall TForm1::Timer(TObject *Sender){...}
然後再由

capPreviewRate(hCapWnd,1000/30);

決定擷取的速度

所以所謂的
void __fastcall TForm1::Timer(TObject *Sender){...}


在整支程式中只有執行一次

我這樣解釋對嘛??

===================引 用 ikk 文 章===================
他放在Form1->OnCreate Event
打開 Object->Inspector的Events tab, 即可看到....
------
恩...
編輯記錄
istillloving 重新編輯於 2009-02-16 23:16:43, 註解 無‧
istillloving 重新編輯於 2009-02-16 23:17:39, 註解 無‧
istillloving 重新編輯於 2009-02-16 23:19:30, 註解 無‧
istillloving 重新編輯於 2009-02-16 23:21:12, 註解 無‧
ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-02-17 08:13:41 IP:163.28.xxx.xxx 訂閱
是的...
Timer()是OnCreate() 的instance...與TTimer元件無關....
------
FPGA驗證, FPGA開發平台, http://smims.com
istillloving
高階會員


發表:33
回覆:182
積分:183
註冊:2008-10-09

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-02-17 23:23:38 IP:218.169.xxx.xxx 訂閱
太感謝您了
取這個名子讓我這個新手怎麼猜都猜不透......
------
恩...
系統時間:2024-03-29 15:35:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!