請教有關Canvas的CopyRect |
答題得分者是:RaynorPao
|
danielj
初階會員 發表:65 回覆:135 積分:40 註冊:2003-06-11 發送簡訊給我 |
小弟想將Form上的Canvas圖像修改後複製到TBitmap的Canvas上,並且存成bmp檔案,但是存成的bmp檔案是空的,能否請各位高手幫忙看看是那裡有問題…
謝謝!
以下是程式碼:
void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) { Graphics::TBitmap *bmp = new Graphics::TBitmap(); Graphics::TBitmap *newbmp = new Graphics::TBitmap(); bmp->LoadFromFile(OpenPictureDialog1->FileName); Canvas->Draw(0,0,bmp); Canvas->Brush->Color = clWhite ; Canvas->Brush->Style = bsClear ; Canvas->Pen ->Color = clBlack ; Canvas->TextOut(Form1->ClientWidth/2,Form1->ClientHeight/2,"TEST"); newbmp->Canvas->CopyRect(TRect(0,0,bmp->Width,bmp->Height), Form1->Canvas,TRect(0,0,bmp->Width,bmp->Height) ); newbmp->SaveToFile("c:\\My Documents\\newbmp.bmp"); bmp->SaveToFile("c:\\My Documents\\txtbmp.bmp"); delete bmp; } } |
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 小弟想將Form上的Canvas圖像修改後複製到TBitmap的Canvas上,並且存成bmp檔案,但是存成的bmp檔案是空的,能否請各位高手幫忙看看是那裡有問題… 謝謝! 以下是程式碼:void __fastcall TForm1::Button1Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) { Graphics::TBitmap *bmp = new Graphics::TBitmap(); Graphics::TBitmap *newbmp = new Graphics::TBitmap(); bmp->LoadFromFile(OpenPictureDialog1->FileName); Canvas->Draw(0,0,bmp); Canvas->Brush->Color = clWhite ; Canvas->Brush->Style = bsClear ; Canvas->Pen ->Color = clBlack ; Canvas->TextOut(Form1->ClientWidth/2,Form1->ClientHeight/2,"TEST"); newbmp->Width=bmp->Width; newbmp->Height=bmp->Height; newbmp->Canvas->CopyRect(TRect(0,0,bmp->Width,bmp->Height), Form1->Canvas,TRect(0,0,bmp->Width,bmp->Height) ); newbmp->SaveToFile("c:\\My Documents\\newbmp.bmp"); bmp->SaveToFile("c:\\My Documents\\txtbmp.bmp"); delete bmp; } } danielj 你好: (1)試試加入上面那兩行 (2)或參考這一篇 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=36012-- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2003/08/20 12:11:48
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
danielj
初階會員 發表:65 回覆:135 積分:40 註冊:2003-06-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |