Drawing polygons
Polygon takes an array of points as its nly parameter and connects the
points with the pen, then connects the last point to the first to close
the polygon. After drawing the lines, Polygon uses the brush to fill the
area inside the polygon.
void __fastcall TForm1::FormPaint(TObject *Sender)
{
POINT vertices[3];
vertices[0] = Point(0, 0);
vertices[1] = Point(0, ClientHeight);
vertices[2] = Point(ClientWidth, ClientHeight);
Canvas->Polygon(verticies);
}
利用 TBitmap 的 ScanLine 屬性取得圖形的一條掃描線.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
BYTE *ptr;
try {
pBitmap->LoadFromFile("c:\\0\\factory.bmp");
for (int y = 0; y < pBitmap->Height; y++) {
ptr = (BYTE*) pBitmap->ScanLine[y];
for (int x = 0; x < pBitmap->Width; x++)
ptr[x] = (BYTE)y;
}
Canvas->Draw(0, 0, pBitmap);
}
catch (...) {
ShowMessage('error opening file');
}
delete pBitmap;
}
拷貝圖形至剪貼簿
void __fastcall TForm1->Copy1Click(TObject *Sender)
{
Clipboard()->Assign(Image1->Picture);
}
把圖形剪到剪貼簿 (=拷貝圖形至剪貼簿後再將圖形清掉)
void __fastcall TForm1->Cut1Click(TObject *Sender)
{
TRect ARect;
Copy1Click(Sender); // 先拷貝
Image1->Canvas->CopyMode = cmWhiteness; // copy every as white
ARect = Rect(0, 0, Image1->Width, Image1->Height); // get image size
Image1->Canvas->CopyRect(ARect, Image1->Canvas, ARect); // copy image over self
Image1->Canvas->Copymode = cmSrcCopy; // restore default mode
}
從剪貼簿貼上圖形
void __fastcall TForm1->Paste1Click(TObject *Sender)
{
Graphics::TBitmap *pBitmap;
if (Clipboard()->HasFormat(CF_BITMAP)) {
pBitmap = new Graphics::TBitmap();
try {
pBitmap->Assign(Clipboard());
Image1->Canvas->Draw(0, 0, pBimap);
delete pBitmap;
}
catch (...) {
delete pBitmap;
}
}
}
               (
geocities.com/huanlin_tsai)