你的方式是將取到影像存成檔案後再重新讀進來,這是利用TMemoryStream 功能,加上CALLBACK FUNTION 功能,這樣就不會因TIME的問題造成DELEY,不知如何上傳執行檔,只能上傳圖檔,如果需要再MAIL給我吧,先貼上SOURCE CODE。 #include
#pragma hdrstop
#include "Unit1.h"
#include
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
HWND GetCapWnd;
LRESULT CALLBACK GetVideo( HWND hwnd, Longint lpvideo );
//---------------------------------------------------------------------------
LRESULT CALLBACK GetVideo( HWND hwnd, Longint lpvideo )
{
LPVIDEOHDR VideoStr;
static BITMAPINFO Bitmap_Info;
static BITMAPINFOHEADER Bitmap_Info_Head;
static BITMAPFILEHEADER Bitmap_File_Head;
CAPSTATUS status;
int BIHsize, byte,gray;
int r,g,b;
int threshold;
Byte *ptr,*ptr1;
TMemoryStream *stream = new TMemoryStream;
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
VideoStr=LPVIDEOHDR(lpvideo);
capGetStatus( GetCapWnd, &status, sizeof(status) ) ;
BIHsize=capGetVideoFormatSize( GetCapWnd );
capGetVideoFormat( GetCapWnd, &Bitmap_Info_Head, BIHsize);
Bitmap_Info.bmiHeader=Bitmap_Info_Head;
stream->Size=sizeof(Bitmap_File_Head) sizeof(Bitmap_Info_Head) Bitmap_Info_Head.biSizeImage;
Bitmap_File_Head.bfType=0x4D42;
Bitmap_File_Head.bfSize=stream->Size;
Bitmap_File_Head.bfOffBits=sizeof(Bitmap_File_Head) sizeof(Bitmap_Info_Head);
stream->Position=0;
stream->WriteBuffer( &Bitmap_File_Head, sizeof(Bitmap_File_Head) );
stream->WriteBuffer( &Bitmap_Info, sizeof(Bitmap_Info) );
(void*)ptr=stream->Memory;
ptr =ptr Bitmap_File_Head.bfOffBits;
Move( VideoStr->lpData, ptr, Bitmap_Info_Head.biSizeImage); stream->Position=0; //歸0
threshold=MainForm->ScrollBar1->Position;
MainForm->Edit1->Text=MainForm->ScrollBar1->Position;
Bmp->LoadFromStream(stream) ;
for(int j=0;jHeight;j )
{
ptr1 = (Byte *)Bmp->ScanLine[j];
for(int i=0;iWidth;i )
{
b=ptr1[i*3];
g=ptr1[i*3 1];
r=ptr1[i*3 2];
gray=0.299*r 0.587*g 0.114*b;
if(gray>threshold)
gray=255;
else
gray=0;
ptr1[i*3]=(Byte)gray;
ptr1[i*3 1]=(Byte)gray;
ptr1[i*3 2]=(Byte)gray;
}
} //二值化結束 MainForm->Image1->Picture->Bitmap=Bmp;
delete stream ;
return(0);
} //---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TMainForm::Edit1Change(TObject *Sender)
{
Edit1->Text=ScrollBar1->Position;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender)
{
GetCapWnd = capCreateCaptureWindow ( "",WS_CHILD | WS_VISIBLE ,0,0,Panel1->Width,Panel1->Height,Panel1->Handle, 0);
bool ccd_ready = false;
ccd_ready=capDriverConnect(GetCapWnd,0);
if( !ccd_ready )
{
ShowMessage("攝影機連接失敗..");
return;
}
capPreviewRate(GetCapWnd,100);
capPreview(GetCapWnd,true);
capSetCallbackOnFrame (GetCapWnd, &GetVideo);
}