问题
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.
- The line length was exactly the custom dash pattern length. Changing the line length +/- 1 pixel avoided the error.
- I was using
LineCapRound
andDashCapRound
, switching toLineCapSquare
andDashCapFlat
avoided the error - The error came from trying flatten the path (presumably from the rounded ends)
- 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