GDI+ DashStyle throws OutOfMemoryException in .NET

心已入冬 提交于 2019-12-11 10:41:51

问题


I'm using DashStyle.Dash while rendering my hierarchy of objects. My application uses Graphics.Transform extensively and I find that at some scale values (including a scale of 100%) and some angles of rotation, Graphics.DrawLine throws OutOfMemoryException when using a pen with DashStyle.Dash. Using Google I found that this is a well-known problem. Microsoft tells us that this is not a blocking issue. So far, I have not found a workaround for this problem.

What are my options?


回答1:


I just encountered the same issue. Upon further investigation I discovered the following.

  1. The line length was exactly the custom dash pattern length. Changing the line length +/- 1 pixel avoided the error.
  2. I was using LineCapRound and DashCapRound, switching to LineCapSquare and DashCapFlat avoided the error
  3. The error came from trying flatten the path (presumably from the rounded ends)
  4. The pen width was zero.

My final solution was to not draw zero width lines!



来源:https://stackoverflow.com/questions/878402/gdi-dashstyle-throws-outofmemoryexception-in-net

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