Download presentation
1
Работа с графикой в C++ Builder
Лекция №3 Работа с графикой в C++ Builder
2
Основные понятия Canvas (канва, холст) – область компонента, на которой можно рисовать или отображать готовые изображения 10 20 Canvas->Pixels[10][20] = clBlue;
3
Рисование линий void __fastcall MoveTo(int X, int Y);
void __fastcall LineTo(int X, int Y); void __fastcall MoveTo(int X, int Y); void __fastcall LineTo(int X, int Y); void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->MoveTo(20, 15); Canvas->LineTo(255, 82); }
4
Рисование линий void __fastcall TForm1::FormPaint(TObject *Sender) {
Canvas->MoveTo(60, 20); Canvas->LineTo(60, 122); Canvas->LineTo(264, 122); Canvas->LineTo(60, 20); }
5
Рисование полилинии void __fastcall Polyline(const Types::TPoint* Points, const int Points_Size); void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[] = { Point(60, 20), Point(60, 122) }; Canvas->MoveTo(Pt[0].x, Pt[0].y); Canvas->LineTo(Pt[1].x, Pt[1].y); } void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[7]; Pt[0] = Point(20, 50); Pt[1] = Point(180, 50); Pt[2] = Point(180, 20); Pt[3] = Point(230, 70); Pt[4] = Point(180, 120); Pt[5] = Point(180, 90); Pt[6] = Point(20, 90); Canvas->Polyline(Pt, 7); }
6
Рисование полилинии void __fastcall TForm1::FormPaint(TObject *Sender)
{ TPoint Pt[7]; Pt[0] = Point(20, 50); Pt[1] = Point(180, 50); Pt[2] = Point(180, 20); Pt[3] = Point(230, 70); Pt[4] = Point(180, 120); Pt[5] = Point(180, 90); Pt[6] = Point(20, 90); HDC hDC = Canvas->Handle; Canvas->MoveTo(20, 30); PolylineTo(hDC, Pt, 7); Canvas->LineTo(20, 110); }
7
Рисование полилинии void __fastcall TForm1::FormPaint(TObject *Sender)
{ TPoint Pt[15]; DWORD lpPts[] = { 4, 4, 7 }; // Figure 1 Pt[0] = Pt[3] = Point(50, 20); Pt[1] = Point(20, 60); Pt[2] = Point(80, 60); // Figure 2 Pt[4] = Pt[7] = Point(70, 20); Pt[5] = Point(100, 60); Pt[6] = Point(130, 20); // Figure 3 Pt[8] = Pt[14] = Point(145, 20); Pt[9] = Point(130, 40); Pt[10] = Point(145, 60); Pt[11] = Point(165, 60); Pt[12] = Point(180, 40); Pt[13] = Point(165, 20); HDC hDC = Canvas->Handle; PolyPolyline(hDC, Pt, lpPts, 3); }
8
Рисование полигона void __fastcall TForm1::FormPaint(TObject *Sender)
{ TPoint Pt[7]; Pt[0] = Point(20, 50); Pt[1] = Point(180, 50); Pt[2] = Point(180, 20); Pt[3] = Point(230, 70); Pt[4] = Point(180, 120); Pt[5] = Point(180, 90); Pt[6] = Point(20, 90); Canvas->Polygon(Pt, 7); }
9
Рисование полигона void __fastcall TForm1::FormPaint(TObject *Sender) { TPoint Pt[12]; int lpPts[] = { 3, 3, 3, 3 }; // Top Triangle Pt[0] = Point(125, 10); Pt[1] = Point( 95, 70); Pt[2] = Point(155, 70); // Left Triangle Pt[3] = Point( 80, 80); Pt[4] = Point( 20, 110); Pt[5] = Point( 80, 140); // Bottom Triangle Pt[6] = Point( 95, 155); Pt[7] = Point(125, 215); Pt[8] = Point(155, 155); // Right Triangle Pt[9] = Point(170, 80); Pt[10] = Point(170, 140); Pt[11] = Point(230, 110); HDC hDC = Canvas->Handle; PolyPolygon(hDC, Pt, lpPts, 4); }
10
Рисование прямоугольников
void __fastcall Rectangle(int X1, int Y1, int X2, int Y2); Canvas->Rectangle(20, 20, 226, 144); void __fastcall TForm1::FormPaint(TObject *Sender) { RECT Recto; Recto.left = 328; Recto.top = 125; Recto.right = 48; Recto.bottom = 25; Canvas->Rectangle(Recto); }
11
Рисование окружностей
void __fastcall Ellipse(int X1, int Y1, int X2, int Y2); Canvas->Ellipse(20, 20, 226, 144); void __fastcall TForm1::FormPaint(TObject *Sender) { TRect Recto(328, 125, 28, 8); Canvas->Ellipse(Recto); }
12
Характеристики линий void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Pen->Color = clRed; Canvas->MoveTo(20, 15); Canvas->LineTo(255, 82); }
13
Характеристики линий void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Pen->Style = psDashDotDot; Canvas->Pen->Width = 1; Canvas->Pen->Color = TColor(RGB(255, 25, 5)); Canvas->Rectangle(20, 22, 250, 125); }
14
Характеристики кисти void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Brush->Color = static_cast<TColor>(RGB(255, 2, 5)); TPoint Pt[3]; // Top Triangle Pt[0] = Point(125, 10); Pt[1] = Point( 95, 70); Pt[2] = Point(155, 70); Canvas->Brush->Color = clGreen; Canvas->Polygon(Pt, 2); // Left Triangle Pt[0] = Point( 80, 80); Pt[1] = Point( 20, 110); Pt[2] = Point( 80, 140); Canvas->Brush->Color = clRed; // Bottom Triangle Pt[0] = Point( 95, 155); Pt[1] = Point(125, 215); Pt[2] = Point(155, 155); Canvas->Brush->Color = clYellow; // Right Triangle Pt[0] = Point(170, 80); Pt[1] = Point(170, 140); Pt[2] = Point(230, 110); Canvas->Brush->Color = clBlue; }
15
Характеристики кисти void __fastcall TForm1::FormPaint(TObject *Sender) { LOGBRUSH LogBrush; LogBrush.lbStyle = BS_HATCHED; LogBrush.lbColor = RGB(255, 0, 255); LogBrush.lbHatch = HS_DIAGCROSS; HBRUSH NewBrush = CreateBrushIndirect(&LogBrush); Canvas->Brush->Handle = NewBrush; Canvas->Rectangle(20, 12, 250, 175); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.