开发者

How to convert a System.Drawing.Drawing2D.LinearGradientBrush to a System.Windows.Media.LinearGradientBrush?

I trying to port System.Drawing: public LinearGradi开发者_JAVA技巧entBrush( Rectangle rect, Color color1, Color color2, float angle ) to System.Windows.Media . I can get the angle to be correct but I can't get the start and end to be at the corners. I have tried scaling the brush's transform but that ends up messing the angle.

How to convert a System.Drawing.Drawing2D.LinearGradientBrush to a System.Windows.Media.LinearGradientBrush?

System.Drawing.Drawing2D.LinearGradientBrush: http://msdn.microsoft.com/en-us/library/ms142563.aspx

System.Windows.Media.LinearGradientBrush: http://msdn.microsoft.com/en-us/library/ms602517.aspx


The corners are good, the gamma correction looks different. The WPF LinearGradientBrush indeed has a GammaCorrection property. Play with it.


I am calculating my start and end points using the intersection of the gradient axis (red line) and the line (blue) perpendicular to the gradient axis that also intersects a corner of the rectangle.

How to convert a System.Drawing.Drawing2D.LinearGradientBrush to a System.Windows.Media.LinearGradientBrush?


I believe that the point at which you choose the gradient to start will actually be where the center of the gradient is if you are using System.Drawing.Drawing2D. I could be wrong, but it looks like System. are using the beginning of the gradient at that point instead of the center which seems to be leading to a bit of an offset.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜