螢幕上的畫面擷取下來 |
尚未結案
|
tienweiliu
一般會員 發表:1 回覆:1 積分:0 註冊:2004-12-30 發送簡訊給我 |
各位前輩小弟需要把螢幕上的畫面擷取下來 並將其PIXELS存入陣列中
我試過各種方法在RUN 時都會產生Erros 希望大家幫幫忙謝謝!!
以下是我的程式碼
另外可否推薦有關影像處理和BCB的書
/*** Graphics::TBitmap *Bitmap = new Graphics::TBitmap(); HDC SourceDC,DestDC,Bhandle; Byte rawdata[640][50]; Byte *ptr; int LeftPos = 0; int TopPos = 0; int RightPos = Screen->Width; int BottomPos = Screen->Height; int RectHeight,RectWidth; RectWidth = RightPos-LeftPos; RectHeight = BottomPos-TopPos; SourceDC = CreateDC("DISPLAY",NULL,NULL,NULL); DestDC = CreateCompatibleDC(SourceDC); Bhandle = CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight); SelectObject(DestDC,Bhandle); BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY); Image1->Picture->Bitmap->Handle = Bhandle; Bitmap->Assign(Image1->Picture->Bitmap); //***************************************** for (int y = 0; y < Bitmap->Height; y ) { ptr = (Byte *)Bitmap->ScanLine[y]; for (int x = 0; x < Bitmap->Width; x ) { rawdata[x][y]=pBitmap->Canvas->Pixels[x][y]; //rawdata[x][y]=ptr[x]; }} for (int x = 0; x < Bitmap->Width; x ) { int y=0; ShowMessage(rawdata[x][y]); y ; } delete Bitmap; } |
JerryKuo
版主 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
引言: 各位前輩小弟需要把螢幕上的畫面擷取下來 並將其PIXELS存入陣列中 我試過各種方法在RUN 時都會產生Erros 希望大家幫幫忙謝謝!! 以下是我的程式碼 另外可否推薦有關影像處理和BCB的書tienweiliu你好: 參考這篇文章 【問題】請問如何儲存螢幕上某一區塊的畫面? http://delphi.ktop.com.tw/topic.php?TOPIC_ID=31270 發表人 - jerrykuo 於 2005/01/12 10:49:42 |
tienweiliu
一般會員 發表:1 回覆:1 積分:0 註冊:2004-12-30 發送簡訊給我 |
謝謝大大的指點我已經成功取到螢幕並存檔但我還有一問題為什麼我用SCANLINE 取PIXES 值並存到ARRAY時一直只取到一個值這樣用對嗎?
///**********************************************************
void __fastcall TMainForm::OpenButtonClick(TObject *Sender) { if (OpenPictureDialog1->Execute()) { // open image and read in file header FILE *in; char* filename = OpenPictureDialog1->FileName.c_str(); unsigned char tempdata[32]; in = fopen(filename, "rb"); fread(tempdata, 1 ,32, in); fclose(in); // obtain dimension information SizeY = tempdata[22] tempdata[23]*256 tempdata[24]; SIZEX = tempdata[18] tempdata[19]*256 tempdata[20]; PixelFormat = tempdata[28]; if ((SIZEX > 1300) || (SizeY > 4300)) { ShowMessage("圖檔過大"); return; } Image5->Picture->Bitmap->Height = SizeY; Image5->Picture->Bitmap->Width = SIZEX; Image5->Height = SizeY; Image5->Width = SIZEX; Image5->Picture->Bitmap->LoadFromFile(OpenPictureDialog1->FileName); Image5->Picture->Bitmap->PixelFormat = pf24bit; } long sum = 0; unsigned char max = 0; unsigned char min = 255; // When the pixel format is 24bits, x = 3*sizex if (PixelFormat == 24) { for (int y = 0; y < Image5->Height; y ) { Byte* ptr = (Byte*)Image5->Picture->Bitmap->ScanLine[y]; for (int x = 0; x < 3*SIZEX; x=x 3) { int i = x/3; FirstData[i][y] = ptr[x]; SecondData[i][y] = ptr[x]; ShowMessage( FirstData[i][y]); *************************************************************** //SHOW MESSAGE 只SHOW 一個值 WHY 我如何確定ARRAY中的值是對的???謝謝 大家 請按照版規說明貼上程式 發表人 - jerrykuo 於 2005/01/12 17:17:51 |
baryan
一般會員 發表:0 回覆:3 積分:0 註冊:2004-12-01 發送簡訊給我 |
我按照上面索引的示範程式,發現抓取螢幕畫面都OK~
但是,我的需求是來抓影像檔(就是用 Windows Media Player 隨便播放影片),發現都是抓到黑畫面,不知是哪裡需要補CODE,謝謝!!! void __fastcall TForm1::Button1Click(TObject *Sender)
{
HDC ScreenDC=GetDC(0);
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
pBitmap->PixelFormat = pf24bit;
pBitmap->HandleType = bmDIB; pBitmap->Width = 320 ;
pBitmap->Height = 240 ; StretchBlt(pBitmap->Canvas->Handle,0,0,320,240,ScreenDC,0,0,320,240,SRCCOPY); Image1->Width = 320 ;
Image1->Height = 240 ;
Image1->Canvas->Draw(0,0,pBitmap); ReleaseDC(0,ScreenDC);
delete pBitmap;
}
|
JerryKuo
版主 發表:42 回覆:571 積分:322 註冊:2003-03-10 發送簡訊給我 |
引言: 我按照上面索引的示範程式,發現抓取螢幕畫面都OK~ 但是,我的需求是來抓影像檔(就是用 Windows Media Player 隨便播放影片),發現都是抓到黑畫面,不知是哪裡需要補CODE,謝謝!!! void __fastcall TForm1::Button1Click(TObject *Sender) { HDC ScreenDC=GetDC(0); Graphics::TBitmap *pBitmap = new Graphics::TBitmap(); pBitmap->PixelFormat = pf24bit; pBitmap->HandleType = bmDIB; pBitmap->Width = 320 ; pBitmap->Height = 240 ; StretchBlt(pBitmap->Canvas->Handle,0,0,320,240,ScreenDC,0,0,320,240,SRCCOPY); Image1->Width = 320 ; Image1->Height = 240 ; Image1->Canvas->Draw(0,0,pBitmap); ReleaseDC(0,ScreenDC); delete pBitmap; }baryan你好, 按暫停再抓? |
baryan
一般會員 發表:0 回覆:3 積分:0 註冊:2004-12-01 發送簡訊給我 |
|
mshining
一般會員 發表:9 回覆:16 積分:5 註冊:2004-12-24 發送簡訊給我 |
|
weme
一般會員 發表:1 回覆:2 積分:0 註冊:2005-03-16 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |