Learn more about GDI + [73]: Region (2)-Region Calculation

Source: Internet
Author: User
Intersect {intersection} Union {Union} XOR _ {minus intersection} exclude {minus} complement {not intersection} // The region of GDI + can be carried out with three objects: rectangle, path, and another region. operation.

  

In this example:


Code File:
Unit unit1; interfaceuses 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 paths} path: = tgpgraphicspath. create; Path. addellipse (20, 20,100, 80); {create a region based on the path} RGN: = tgpregion. create (PATH); {get the range} // RGN. getbounds (RT, g); Path. getbounds (RT); {move down the rectangle and use this rectangle to perform operations} 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.
 
   
 

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 = pow.topcenter 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 endend

  

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.