全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1656
推到 Plurk!
推到 Facebook!

螢幕上的畫面擷取下來

尚未結案
tienweiliu
一般會員


發表:1
回覆:1
積分:0
註冊:2004-12-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-11 17:38:03 IP:61.61.xxx.xxx 未訂閱
各位前輩小弟需要把螢幕上的畫面擷取下來 並將其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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-12 10:48:45 IP:220.135.xxx.xxx 未訂閱
引言: 各位前輩小弟需要把螢幕上的畫面擷取下來 並將其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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-12 11:32:36 IP:61.61.xxx.xxx 未訂閱
謝謝大大的指點我已經成功取到螢幕並存檔但我還有一問題為什麼我用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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-12 20:09:27 IP:211.76.xxx.xxx 未訂閱
我按照上面索引的示範程式,發現抓取螢幕畫面都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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-01-13 09:03:12 IP:220.135.xxx.xxx 未訂閱
引言: 我按照上面索引的示範程式,發現抓取螢幕畫面都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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-01-13 10:36:34 IP:211.76.xxx.xxx 未訂閱
Sorry ~ 我是使用VLC這套軟體(eDonkey or eMule 的default 預覽影片SW) 我也是有按暫停後再去抓!但是不行~~ PS.用 MS Windows Media Player 播放影片就可以抓取!!! (抓取方法:複製全螢幕然後貼到小畫家)
mshining
一般會員


發表:9
回覆:16
積分:5
註冊:2004-12-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-05-16 13:59:46 IP:61.62.xxx.xxx 未訂閱
baryan~你好 請問你抓到黑畫面的問題解決了嗎? 目前我也碰到相同的情形了 使用GetDC去抓Panel 有的時後會抓到~但是偶爾會出現一、二張黑畫面 可以麻煩指導一下嗎? 謝謝!
weme
一般會員


發表:1
回覆:2
積分:0
註冊:2005-03-16

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-07-08 14:02:49 IP:203.70.xxx.xxx 未訂閱
會擷取不到 畫面 可能是因為 MS Windows Media Player 等 撥放軟體 通常是用 direct draw 的方式 直接顯示於顯示卡記憶體上 所以 若有此問題應先把 direct draw 關閉停用 使得 撥放軟體 將影像 顯示於系統顯示記憶體 才能攫取得到... weme
------
weme
系統時間:2024-05-06 1:00:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!