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

IdTCPClient \ IdTCPServer收發CCD擷取之TMemoryStream的問題

尚未結案
kttseng2001
一般會員


發表:2
回覆:3
積分:1
註冊:2003-08-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-02-08 00:05:01 IP:61.219.xxx.xxx 未訂閱
各位前輩大家好,小弟參照版上的許多作品,欲利用IdTCPServer發送由WebCam所擷取的TMemoryStream至Client端做處理,但是不知道哪裡出了錯,接收影像時會出現Otu of memory while expending memory stream的訊息,小弟的程式如下,煩請前輩們多多指教。謝謝。     
Server端:    //---------------------------------------------------------------------------    #include 
#include 
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdBaseComponent"
#pragma link "IdComponent"
#pragma link "IdTCPServer"
#pragma link "IdIPWatch"
#pragma resource "*.dfm"
TForm1 *Form1;    HWND GetCapWnd;
LPVIDEOHDR VideoStr;
LRESULT CALLBACK GetVideo( HWND hwnd, Longint lpvideo );
TMemoryStream *stream = new TMemoryStream;    //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
IdTCPServer1->DefaultPort=4000;          //IdTCPServer1元件
IdTCPServer1->Active=true;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK GetVideo( HWND hwnd, Longint lpvideo )
{
static BITMAPINFO Bitmap_Info;
static BITMAPINFOHEADER Bitmap_Info_Head;
static BITMAPFILEHEADER Bitmap_File_Head;
CAPSTATUS status;
int BIHsize;
Byte *ptr,*ptr1;    //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->Clear();
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
//Bmp->LoadFromStream(stream);
//Form1->Image1->Picture->Bitmap=Bmp;
return(0);
}    //---------------------------------------------------------------------------
void __fastcall TForm1::N2Click(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,50);
capPreview(GetCapWnd,true);
capSetCallbackOnFrame (GetCapWnd, &GetVideo);    }
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
capDlgVideoSource(GetCapWnd);
capDlgVideoFormat(GetCapWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
capDriverDisconnect(GetCapWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
{
AnsiString szCommand=AThread->Connection->ReadLn(EOL,300,1000);
if(szCommand=="ServerToClient")
{
AThread->Connection->WriteStream(stream, true, true, 0);
//stream->Size=0;
}
else if(szCommand=="Stop")
{
capDriverDisconnect(GetCapWnd);
IdTCPServer1->Active=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StatusBar1->Panels->Items[0]->Text="IP:" IdIPWatch1->LocalIP() ;    //IdIPWatch1元件
StatusBar1->Panels->Items[1]->Text="Port:" IntToStr(IdTCPServer1->DefaultPort);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
IdTCPServer1->Active=false;
}
//---------------------------------------------------------------------------        Client 端:    //---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "IdBaseComponent"
#pragma link "IdComponent"
#pragma link "IdTCPClient"
#pragma link "IdTCPConnection"
#pragma resource "*.dfm"
TForm1 *Form1;
TMemoryStream *ms1=new TMemoryStream;    //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{    }
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
IdTCPClient1->Host=Edit1->Text;
IdTCPClient1->Port=StrToInt(Edit2->Text);
IdTCPClient1->Connect(3000);
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(IdTCPClient1->Connected())
{    Graphics::TBitmap *bmp1=new Graphics::TBitmap;    IdTCPClient1->WriteLn("ServerToClient");
IdTCPClient1->ReadStream(ms1, -1, false);
ms1->Position=0;
bmp1->LoadFromStream(ms1);
Image1->Picture->Bitmap=bmp1;
delete bmp1;
ms1->Clear();
}    }
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
IdTCPClient1->WriteLn("Stop");
IdTCPClient1->Disconnect();
}
//---------------------------------------------------------------------------    void __fastcall TForm1::FormCreate(TObject *Sender)
{
Image1->Canvas->Brush->Style=bsSolid;
Image1->Canvas->Brush->Color=clBlack;
Image1->Canvas->Rectangle(0,0,160,120);
}
//---------------------------------------------------------------------------         
Ktop_Robot
站務副站長


發表:0
回覆:3511
積分:0
註冊:2007-04-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-04-18 17:33:14 IP:000.000.xxx.xxx 未訂閱
提問者您好:


以上回應是否已得到滿意的答覆?


若已得到滿意的答覆,請在一週內結案,否則請在一週內回覆還有什麼未盡事宜,不然,
將由版主(尚無版主之區域將由副站長或站長)自由心證,選擇較合適之解答予以結案處理,
被選上之答題者同樣會有加分獎勵同時發問者將受到扣 1 分的處分。不便之處,請見諒。


有問有答有結案,才能有良性的互動,良好的討論環境需要大家共同維護,感謝您的配合。

------
我是機器人,我不接受簡訊.
系統時間:2024-05-02 18:26:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!