GDI+中region to graphicspath问题.请高手分析一下
Graphics graphics(this->m_hWnd);
SolidBrush solidBrush(Color(255, 255, 0, 0));
Pen pen(Color(255, 0, 0, 0));
GraphicsPath path;
Matrix matrix;
Rect* rects = NULL;
INT count = 0;
// Create a region from a path.
path.AddEllipse(Rect(10, 10, 300, 300));
// path.AddEllipse(100, 10, 300, 300);
Region pathRegion(&path);
// pathRegion.Union(Rect(100, 10, 300, 300));
// graphics.FillRegion(&solidBrush, &pathRegion);
graphics.DrawPath(&pen,&path );
// Get the rectangles.
graphics.GetTransform(&matrix);
count = pathRegion.GetRegionScansCount(&matrix);
rects = (Rect*)malloc(count*sizeof(Rect));
pathRegion.GetRegionScans(&matrix, rects, &count);
graphics.TranslateTransform(300,0);
GraphicsPath path1;
path1.AddRectangles(rects,count);
path1.Outline();
graphics.DrawPath(&pen,&path1);
free(rects);
上述代码拷贝到ondraw消息中可以直接测试.
功能:为了将region的边界转换为path.在本例中区域中只有一个圆,在实际情况中可能要比这个复杂得多.
问题:画出来的效果是下半部分可以得到边界,但上半部分却得不到.具体情况以实际运行结果为准.
目的:为了实现对多个path调用了outline()后的路径进行合并操作(这个相对容易些),减操作(难点在于此).直接进行操作可能不现实,需要将path转为region然后对region进行减操作后再转换为path.
评审:有点曲折,但小弟已经没有别的办法了.
解决办法:希望各位能点拨一下.或者给出新的解决方案.
谢谢!