Equality of GDI+ Regions

心不动则不痛 提交于 2020-02-04 20:43:50

问题


Why does the assertion fail in the following code? Why aren't regions a and b equal?

  Region a = new Region(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
  Region b = new Region();
  b.MakeEmpty();
  b.Union(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f));
  Debug.Assert(a == b, "Regions not equal");

回答1:


From what I can see, System.Drawing.Region does not override Object's implementation of Equals(). Therefore your == call is using ReferenceEquals and simply telling you a and b are not the same object.

Try using the System.Drawing.Region.Equals(Region, Graphics) overload instead, passing in a Graphics object in the context you wish to compare the two regions.



来源:https://stackoverflow.com/questions/21011679/equality-of-gdi-regions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!