Learn more about GDI + [50]: Path-getpathpoints, getpathtypes, tpathdata, getpathdata

Source: Internet
Author: User
This example has an error! The point type is often not single;

For example, a point may be a sub-path end point, a curve point, or a mark point at the same time. A type value is a combination of three types.

Unfortunately, I still don't know about this example. Put it here, leave a souvenir, and write down the childishness!

In this example:


Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, grids; Type tform1 = Class (tform) stringgrid1: tstringgrid; procedure formcreate (Sender: tobject); Procedure formpaint (Sender: tobject); Procedure outputs (Sender: tobject; ACOl, Arow: integer; var canselect: Boolean); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; Procedure tform1.formcreate (Sender: tobject); begin stringgrid1.align: = alright; direction: = 0; stringgrid1.colcount: = 3; Direction [0]: = 25; stringgrid1.colwidths [1]: = 25; stringgrid1.colwidths [2]: = 80; Digest: = 20; stringgrid1.cells []: = 'X'; stringgrid1.cells []: = 'y'; stringgrid1.cells [2, 0]: = 'vertex type'; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; P: tgppen; Path: tgpgraphicspath; points: array of tgppoint; types: pbyte; typestr: string; I: integer; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (aclred); Path: = tgpgraphicspath. create; Path. startfigure; Path. addrectangle (makerect (30,20, 90,40); Path. addellipse (makerect (30, 80, 90,180); Path. closefigure; G. drawpath (p, PATH); setlength (points, path. getpointcount); getmem (types, path. getpointcount); Path. getpathpoints (pgppoint (points), length (points); Path. getpathtypes (types, length (points); stringgrid1.rowcount: = length (points) + 1; for I: = 0 to length (points) -1 do begin case types ^ of $00: typestr: = 'path start point'; $01: typestr: = 'line point'; $03: typestr: = 'besser'; $07: typestr: = 'fill point'; $10: typestr: = 'dotted dot '; $20: typestr: = 'path tag '; $80: typestr: = 'child path end point'; end; stringgrid1.cells [0, I + 1]: = inttostr (points [I]. x); stringgrid1.cells [1, I + 1]: = inttostr (points [I]. y); stringgrid1.cells [2, I + 1]: = typestr; Inc (types); end; Dec (types, length (points); freemem (types); types: = nil; Path. free; p. free; G. free; end; Procedure tform1.stringgrid1selectcell (Sender: tobject; ACOl, Arow: integer; var canselect: Boolean); var X, Y: integer; begin X: = strtointdef (stringgrid1.cells [0, arow], 0); y: = strtointdef (stringgrid1.cells [1, Arow], 0); repaint; canvas. brush. color: = clblue; canvas. fillrect (bounds (X-3, Y-3, 6); text: = format ('% d, % d', [x, y]); end.
 
   
 

This example is a little troublesome. If you use the tpathdata class, it will be much simpler. below is the Code implemented with tpathdata, and the running effect is the same. However, the obtained vertex array must be a decimal array. The Code is as follows:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, grids; Type tform1 = Class (tform) stringgrid1: tstringgrid; procedure formcreate (Sender: tobject); Procedure formpaint (Sender: tobject); Procedure outputs (Sender: tobject; ACOl, Arow: integer; var canselect: Boolean); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; Procedure tform1.formcreate (Sender: tobject); begin stringgrid1.align: = alright; direction: = 0; stringgrid1.colcount: = 3; Direction [0]: = 25; stringgrid1.colwidths [1]: = 25; stringgrid1.colwidths [2]: = 80; Digest: = 20; stringgrid1.cells []: = 'X'; stringgrid1.cells []: = 'y'; stringgrid1.cells [2, 0]: = 'vertex type'; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; P: tgppen; Path: tgpgraphicspath; pathdata: tpathdata; points: pgppointf; types: pbyte; typestr: string; I: integer; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (aclred); Path: = tgpgraphicspath. create; Path. startfigure; Path. addrectangle (makerect (30,20, 90,40); Path. addellipse (makerect (30, 80, 90,180); Path. closefigure; G. drawpath (p, PATH); pathdata: = tpathdata. create; Path. getpathdata (pathdata); points: = pathdata. points; types: = pathdata. types; stringgrid1.rowcount: = pathdata. count + 1; for I: = 0 to pathdata. count-1 do begin case types ^ of $00: typestr: = 'path start point'; $01: typestr: = 'line point'; $03: typestr: = 'besser'; $07: typestr: = 'fill point'; $10: typestr: = 'dotted dot '; $20: typestr: = 'path tag '; $80: typestr: = 'child path end point'; end; stringgrid1.cells [0, I + 1]: = inttostr (trunc (points. x); stringgrid1.cells [1, I + 1]: = inttostr (trunc (points. y); stringgrid1.cells [2, I + 1]: = typestr; Inc (points); Inc (types); end; pathdata. free; Path. free; p. free; G. free; end; Procedure tform1.stringgrid1selectcell (Sender: tobject; ACOl, Arow: integer; var canselect: Boolean); var X, Y: integer; begin X: = strtointdef (stringgrid1.cells [0, arow], 0); y: = strtointdef (stringgrid1.cells [1, Arow], 0); repaint; canvas. brush. color: = clblue; canvas. fillrect (bounds (X-3, Y-3, 6); text: = format ('% d, % d', [x, y]); end.
 
   
 

Form file:

 
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 276 clientwidth = 303 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 stringgrid1: tstringgrid left = 88 Top = 40 width = 154 Height = 120 taborder = 0 onselectcell = stringgrid1selectcell endend

  

Enumeration of point types in the path:

 pathpointtype = (pathpointtypestart = $00, {path start point} pathpointtypeline = $01, {Line point} pathpointtypebezr = $03, {default bersel line point} pathpointtypepathtypemask =07 07, {covering point} pathpointtypedashmode =10 10, {dotted line point} pathpointtypepathmarker =20 20, {path tag} pathpointtypeclosesubpath = $80, {sub-path end point} pathpointtypebezier3 =03 03 {stereo besell line point}); tpathpointtype = pathpointtype;

   

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.