Re-learning gdi+[73]: Area (2)

Source: Internet
Author: User

Intersect {交集}
Union   {联合}
Xor_    {减去交集}
Exclude  {减去}
Complement {不相交}
//GDI+ 的区域能和矩形、路径、另一个区域三种对象进行运算.

This example effect chart:

Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Extctrls;
Type
TForm1 = Class (Tform)
Radiogroup1:tradiogroup;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Radiogroup1click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Procedure Tform1.formcreate (Sender:tobject);
Begin
RadioGroup1.Items.CommaText: = ' channel, rectangle, intersect,union,xor_,exclude,complement ';
Radiogroup1.itemindex: = 0;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
Path:tgpgraphicspath;
B:tgpbrush;
Rgn:tgpregion;
Rt:tgprect;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = tgppen.create (Makecolor (100, 255, 0, 0));
B: = Tgphatchbrush.create (Hatchstylesmallgrid, Aclsilver, Aclcornflowerblue);
{Prepare a path}
Path: = Tgpgraphicspath.create;
Path. AddEllipse (20, 20, 100, 80);
{Create zone based on path}
Rgn: = tgpregion.create (path);
{Get spacing}
Rgn. GetBounds (RT, G);
Path. GetBounds (RT);
{Move the rectangle down, and use this rectangle to perform the operation on the above area}
Rt. Y: = Rt. Y + Rt. Height Div 2;
Case Radiogroup1.itemindex of
1:rgn: = Tgpregion.create (RT);
2:rgn. Intersect (RT);
3:rgn. Union (RT);
4:rgn. Xor_ (RT);
5:rgn. Exclude (RT);
6:rgn.complement (RT);
End
G.fillregion (b, RGN);
G.drawpath (P, path);
G.drawrectangle (P, RT);
B.free;
Rgn. Free;
P.free;
G.free;
End
Procedure Tform1.radiogroup1click (Sender:tobject);
Begin
Repaint;
End
End.

Form file:object Form1: TForm1
 Left = 0
 Top = 0
 Caption = 'Form1'
 ClientHeight = 167
 ClientWidth = 238
 Color = clBtnFace
 Font.Charset = DEFAULT_CHARSET
 Font.Color = clWindowText
 Font.Height = -11
 Font.Name = 'Tahoma'
 Font.Style = []
 OldCreateOrder = False
 Position = poDesktopCenter
 OnCreate = FormCreate
 OnPaint = FormPaint
 PixelsPerInch = 96
 TextHeight = 13
 object RadioGroup1: TRadioGroup
  Left = 137
  Top = 8
  Width = 91
  Height = 151
  Caption = 'RadioGroup1'
  TabOrder = 0
  OnClick = RadioGroup1Click
 end
end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.