We know that in GDI +, we can use the region. Union method to merge the regions (region) of two graphic paths (graphicspath. However, it is no longer possible to obtain the graphicspath of the merged region. For example, the red part of 1:
Figure 1 effect achieved after graphicspath is merged
It consists of two ovans:
Rectangle rect1 = new rectangle (100,100,178,178 );
Rectangle rect2 = new rectangle (230,100,178,178 );
Graphicspath Gp = new graphicspath (fillmode. Winding );
GP. addellipse (rect1 );
GP. addellipse (rect2 );
Bitmap BMP = new Bitmap (520,520 );
Graphics G = graphics. fromimage (BMP );
G. compositingquality = compositingquality. highquality;
G. interpolationmode = interpolationmode. highqualitybicubic;
G. textrenderinghint = system. Drawing. Text. textrenderinghint. antialias;
G. smoothingmode = smoothingmode. highquality;
G. drawpath (new pen (color. Red, 3f), GP );
Picencode. Image = BMP;
But the above Code does not get the result of Figure 1, but the style shown in Figure 2:
Figure 2 use the graphicspath. Add () method to generate a corridor drawing for two graphic paths
Is there a way to truly merge the two graphicspath?
First, let's take a look at the stuff behind graphicspath: GP. pathdata, which contains the points and types arrays of the path.
For each point, byte values 0 to 2 indicate the vertex type, and 3 to 7 save a set of attribute flags that can refer to the specified point. The values are as follows:
0 indicates that this point is the starting point of the graph; 1 indicates that this point is one of the two endpoints of the straight line; 3 indicates that this point is the endpoint or control point of the three-way besell curve; 0x7 indicates all bitwise elements of the mask, but it indicates that the three low-level bits of the vertex type are not in this column; 0x20 indicates that this vertex is marked; 0x80 indicates that this vertex is the last vertex of the closed subpath.
This is its original definition:
Typedef Enum {
Pathpointtypestart = 0,
Pathpointtypeline = 1,
Pathpointtypebezr = 3,
Pathpointtypepathtypemask = 0x7,
Pathpointtypepathdashmode = 0x10,
Pathpointtypepathmarker = 0x20,
Pathpointtypeclosesubpath = 0x80,
Pathpointtypebezier3 = 3
} Pathpointtype;
Let's take a look at graphicspath in Figure 2. (use the C # tool to get the secret behind it. Haha ~~) :
Graphicspath Path = new graphicspath (
New pointf [] {
New pointf (278f, 99f), new pointf (278f, 148.1533f), new pointf (partition, 188f), new pointf (189f, 188f), new pointf (139.8466f, 188f ),
New pointf (100f, 148.1533f), new pointf (100f, 99f), new pointf (100f, 49.84666f), new pointf (139.8466f, 10f), new pointf (189f, 10f ),
New pointf (238.1533f, 10f), new pointf (278f, 49.84666f), new pointf (278f, 99f), new pointf (408f, 99f), new pointf (408f, 148.1533f ),
New pointf (368.1533f, 188f), new pointf (319f, 188f), new pointf (269.8466f, 188f), new pointf (230f, 148.1533f), new pointf (230f, 99f ),
New pointf (230f, 49.84666f), new pointf (269.8466f, 10f), new pointf (319f, 10f), new pointf (368.1533f, 10f), new pointf (408f, expires ),
New pointf (408f, 99f )},
New system. byte [] {0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,131, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3});
Note that the byte array in the last row above has an equivalent value of 131, 131, where 128 is a combination of (0x80) and 3, this is the last point of the closed sub-path and the endpoint of the besell curve.
3 shows the key point (blue indicates the Key Point ):
Figure 3 key points of the graphic path
We can see from the above: the intersection of the left and right circles is not the key point!
The trouble is solved. We must find these intersections and then put them into the last graphicspath as the key point to solve the problem of merging the graphic paths.
How can we find the intersection? It is easy to use regular graphic paths such as rectangles (such as 4) and circles. We can try to use mathematical formulas.
Figure 4 graphicspath constructed by two rectangles (where the blue point is the key point)
The source code in Figure 4 is only to change addellipse in the rough two lines of code in the code shown in Figure 2 to addrectangle. Obviously, it is very easy to find their intersections. However, it becomes very tricky for irregular beiser curves.
If you are interested, you can take a look at this article. It is relatively basic, but very useful. It is only in English. If you are not good at English, please take a look at it and understand it, there will be gains!
Http://processingjs.nihongoresources.com/bezierinfo/
By the way, you can also look at this:
Http://processingjs.nihongoresources.com/bezierinfo/sketchsource.php? Sketch = cubicsubdivision
Http://fei.edu.br /~ Psergio/cg_arquivos/introsplines.pdf
Http://www.uio.no/studier/emner/matnat/ifi/INF3320/h03/undervisningsmateriale/lecture8.pdf
Http://losingfight.com/blog/2011/07/08/how-to-implement-boolean-operations-on-bezier-paths-part-2/
Http://www.cs.berkeley.edu /~ Hling/research/paper/surface.htm
Http://blog.sina.com.cn/s/blog_640531380100q669.html
(To be continued, I am going to discuss this issue in another article)