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

請教有關Canvas的CopyRect

答題得分者是:RaynorPao
danielj
初階會員


發表:65
回覆:135
積分:40
註冊:2003-06-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-20 11:44:07 IP:61.220.xxx.xxx 未訂閱
小弟想將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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-20 12:01:32 IP:203.73.xxx.xxx 未訂閱
引言: 小弟想將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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-20 13:31:53 IP:61.220.xxx.xxx 未訂閱
多謝RaynorPao大大啦! 原來是要給定TBitmap的長寬才可以…
系統時間:2024-05-14 13:40:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!