為什麼我的Mediaplayer 無法抓圖 |
尚未結案
|
techtech
一般會員 發表:3 回覆:3 積分:1 註冊:2003-09-12 發送簡訊給我 |
大家好,我參照論壇的文章,想在Mediaplayer 撥放時,抓取圖像存成bmp檔。可是為什麼我存的檔案都黑嗚嗚的一片。請大家給我指教,謝謝!
[code cpp] #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" int Count=0; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if(OpenDialog1->Execute()) {MediaPlayer1->FileName=OpenDialog1->FileName; MediaPlayer1->Open(); MediaPlayer1->Display=Panel1; MediaPlayer1->DisplayRect=Rect(0,0,640,480); } } //--------------------------------------------------------------------------- void __fastcall TForm1::MediaPlayer1Click(TObject *Sender, TMPBtnType Button, bool &DoDefault) { Byte *ptr1; Graphics::TBitmap *MyBmp; TCanvas *MyCanvas; HDC dc; TRect rect; String name; if((Button == btBack)||(Button == btStep)) { try { MyBmp = new Graphics::TBitmap(); MyCanvas =new TCanvas ; rect = MediaPlayer1->DisplayRect ; dc = GetDC(Panel1->Handle); MyCanvas->Handle = dc; MyBmp->Width = rect.Right - rect.Left ; MyBmp->Height = rect.Bottom - rect.Top ; MyBmp->PixelFormat=pf24bit; MyBmp->Canvas->CopyRect(Rect(0,0,MyBmp->Width,MyBmp->Height),MyCanvas,Rect(0,0,Panel1->Width,Panel1->Height)); Count =Count 1; if(Count<10)name="000" IntToStr(Count); else if(Count<100)name="00" IntToStr(Count); else if(Count<1000)name="0" IntToStr(Count); name = "C:\\" name ".bmp"; MyBmp->SaveToFile(name); } catch(...){} ReleaseDC(0,dc); delete MyBmp; delete MyCanvas; } } [/code] 我用Memo去看MyBmp的值,都是[16 ,0,16],是不是我忽略得什麼? |
tylin123
初階會員 發表:33 回覆:53 積分:32 註冊:2003-05-19 發送簡訊給我 |
這是由於 Mediaplayer 播放的是 Video stream 的資料, 畫面上的資料並不在對應的位址上播放.
建議你使用 DirectShow API 擷取 Video stream 的 frame 然後再進行擷圖. ===================引 用 techtech 文 章=================== 大家好,我參照論壇的文章,想在Mediaplayer 撥放時,抓取圖像存成bmp檔。可是為什麼我存的檔案都黑嗚嗚的一片。請大家給我指教,謝謝! [code cpp] #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" int Count=0; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if(OpenDialog1->Execute()) {MediaPlayer1->FileName=OpenDialog1->FileName; MediaPlayer1->Open(); MediaPlayer1->Display=Panel1; MediaPlayer1->DisplayRect=Rect(0,0,640,480); } } //--------------------------------------------------------------------------- void __fastcall TForm1::MediaPlayer1Click(TObject *Sender, TMPBtnType Button, bool &DoDefault) { Byte *ptr1; Graphics::TBitmap *MyBmp; TCanvas *MyCanvas; HDC dc; TRect rect; String name; if((Button == btBack)||(Button == btStep)) { try { MyBmp = new Graphics::TBitmap(); MyCanvas =new TCanvas ; rect = MediaPlayer1->DisplayRect ; dc = GetDC(Panel1->Handle); MyCanvas->Handle = dc; MyBmp->Width = rect.Right - rect.Left ; MyBmp->Height = rect.Bottom - rect.Top ; MyBmp->PixelFormat=pf24bit; MyBmp->Canvas->CopyRect(Rect(0,0,MyBmp->Width,MyBmp->Height),MyCanvas,Rect(0,0,Panel1->Width,Panel1->Height)); Count =Count 1; if(Count<10)name="000" IntToStr(Count); else if(Count<100)name="00" IntToStr(Count); else if(Count<1000)name="0" IntToStr(Count); name = "C:\\" name ".bmp"; MyBmp->SaveToFile(name); } catch(...){} ReleaseDC(0,dc); delete MyBmp; delete MyCanvas; } } [/code] 我用Memo去看MyBmp的值,都是[16 ,0,16],是不是我忽略得什麼? |
tai721014
一般會員 發表:19 回覆:12 積分:6 註冊:2008-07-02 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |