在TCanvas上画图

来源:互联网 发布:mallat小波分解算法 编辑:程序博客网 时间:2024/04/29 06:39

将一幅bmp图片,从文件中加载到窗口的TCanvas上去,代码如下:

      ::Graphics::TBitmap *bmp= new ::Graphics::TBitmap;      bmp->Transparent = true;//是否透明      bmp->LoadFromFile("right1.bmp");      Canvas->Draw(0,0,bmp);      delete bmp;
在TCanvas上画背景透明的文字,代码如下:

    Image1->Canvas->Font->Color = clRed;   //文字颜色    Image1->Canvas->Brush->Style = bsClear;//文字区域透明    Image1->Canvas->TextOutA(20,0,"大家好");

在TCanvas上画矩形,矩形区域透明

    Image1->Canvas->Brush->Style = bsClear;    Image1->Canvas->Rectangle(51,0,78,28);

在TCanvas上画图后,想擦除刚画形,代码如下:
    Image1->Canvas->Pen->Mode = pmNotXor ;    Image1->Canvas->Pen->Color = clBlue;    Image1->Canvas->Pen->Style = psSolid;    Image1->Canvas->Pen->Width = 1;

将上述代码执行第二次时,擦除第一次所画图形。

在内存中画图,复制到其他的TCanvas上

void __fastcall TForm1::Button1Click(TObject *Sender){    ::Graphics::TBitmap *bmp = new ::Graphics::TBitmap;    bmp->Width = 100;    bmp->Height= 100;    bmp->Canvas->Pen->Color = clRed;    bmp->Canvas->Ellipse(0,0,100,100);    TRect a(0,0,200,200);    TRect b(0,0,200,200);    Canvas->BrushCopy(a, bmp, b, clBlack);    Canvas->CopyMode = SRCCOPY;    //Image1->Picture->Bitmap->Assign(bmp);//后面屏蔽的这几句功能相似。    //Image1->Picture->Bitmap=bmp;    Canvas->CopyRect(a,bmp->Canvas,b);     //BitBlt(this->Canvas->Handle,0,0,100,100,bmp->Canvas->Handle,0,0,SRCCOPY);}



0 0
原创粉丝点击