Recently, I found a weird phenomenon when I was treated with GDI , I couldn't find the explanation on the Internet. I want to be a bug with M $, and I will have a similar experience.
Phenomenon: Assume that there are three RECTs, which are RT1, RT2, and RT3, respectively. Ask their collection area. Use GDIPLUS :: Region to process. As follows: gdiplus :: region reg; reg.makeempty (); reg.union (RT1); reg.ungion (RT2); reg.union (RT3);
Usually, the correct result will be obtained. But if RT1 and RT2 are relared, and not intersect! And RT3 (relatively large) and RT1, RT2 intersect, the actual results will be quirky. The portion of the RT3 in the right side of the RT3 will be cut off the rectangle of an RT1 height.
At this time, if the mobile RT1 makes him intersect with RT2 (even a little bit), the result is immediately normal. If you keep the RT1 and RT2 position (not intersect), slowly move RT3, once RT3 is only intersecting one, or even does not intersect, the result is immediately normal.
This is not the most bizarre, even more weird, if you change the order of Union, make the big rectangular RT3 not in the end, the result is immediately normal. The presentation code is as follows: (GDIPLUSSTARTUP & GDIPLUSSHUTDOWN) #include "gdiplus.h" #pragma Comment (lib, "gdiplus.lib") Using namespace gdiplus; ... cviwe :: Ondraw (CDC * PDC) {Rect RT1 (54 , 107, 92, 77); Rect RT2 (168, 16, 92, 117); RECT RT3 (116, 70, 632, 150);
Region reg; reg.makeempty ();
REG.Union (RT1); Reg.union (RT2); Reg.union (RT3);
Graphics G (PDC-> GetsafeHDC ());
Solidbrush Brush (Color (128, 255, 0, 0));
G.FillRegion (& brush, & reg);
This will get a weird result. If REG.Union (RT3) is placed in front of Reg.Union (RT2), the result is correct.
Tried another version of Union, the same effect.
If you don't use GDI , use a traditional RGN, the result is correct, no matter how it is correct.
BUG reproduces points: RT1 and RT2 side by side, and there is a gap. RT3 is wider, and there is no problem with the height, but the high height is highly easy to see. RT3 and RT1, RT2 are overlap, and the right side has exceeded RT2. The longer the right side is more obvious. The left jump of RT3 does not jump over the left side of RT1, it doesn't matter, it is easy to see the effect.
Most importantly, when UNION, the largest RT3 will be placed in the end, and there will be a weird effect. C # also appears as a bug. Demonstration code is as follows: Private void onpaint (Object sender, system.windows.forms.painteventargs e) {Rectangle RT1 = New Rectangle (54, 107, 92, 77); Rectangle RT2 = New Rectangle (168 , 16, 92, 117); Rectangle RT3 = New Rectangle (40, 70, 632, 150); region reg = new region (); reg.makeempty ();
REG.Union (RT1); Reg.union (RT2); Reg.union (RT3);
Solidbrush brush = new solidbrush (color.blue);
E.Graphics.FillRegion (Brush, REG);} Turns Reg.Union (RT3) to the front, can also return to normal. The conclusion is that the rectangular height and position of the rt3 is not normal is RT1 and RT2 at a height intersecting portion, and the width starts from the right side of RT2, until the right side of RT3. More than 2 rectangles are rolled away, with gaps in the middle, the effect is more complicated. Every left rectangle will generate a corresponding cutting effect on the right.