SVG-> WPF线性渐变
有谁知道WPF中的LinearGradientBrush是否有SVG的“gradientUnits=userSpaceOnUse”的等效属性?我好像找不到这个
如果没有,有人知道如何用(C# 或 VB.NET)计算它吗?例如,如果我在 100x100 的矩形上的起点为 0,0,终点为 1,1,则角度为 45 度。但是,当我更改矩形的宽度或高度(例如宽度=150)时,轴不再是 45 度。我怎样才能计算出在不是正方形的矩形中保持 45 度的角度,以便它从左下角延伸到右上角以形成中间渐变停止点。
Does anyone know if there is an equilant attribute of SVG's "gradientUnits=userSpaceOnUse" in WPF for a LinearGradientBrush? I can't seem to find this.
If not, does anyone know about how to calculate it in (C# or VB.NET)? For example if I have a StartPoint of 0,0 and EndPoint of 1,1 on a Rectangle that is 100x100, the angle is 45 degrees. However, when I change either the width or height of the Rectangle, for example Width=150, the axis is no longer at 45 degrees. How could I calculate to keep the angle at 45 degrees in a rectangle that is not a square so that it runs from bottom left to top right corner for a middle gradientstop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置画笔MappingMode = BrushMappingMode.Absolute
Set the brush MappingMode = BrushMappingMode.Absolute
这在新的 Silverlight 4 中就像一个魅力 - 在 RotateTransform 中将角度设置为 45 度,这样可以针对边界框而不是形状。像这样:
This works like a charm now in the new Silverlight 4 - setting the angle to 45 degrees in RotateTransform does so for the bounding box instead of the shape. Like this: