绘制一条从一种颜色混合到另一种颜色的线条
在 WPF 中,有没有办法绘制一条从一种颜色混合到另一种颜色的线(在任何方向)?
例如,我想从A点到B点画一条线,其中A是红色,B是黑色。该线可以是垂直的、水平的或任何方向。
我尝试过使用 LinearGradientBrush,但这需要您设置角度或开始/结束位置。这对我来说不起作用,因为我需要能够在任何方向的任意两点绘制线条,并且仍然让它混合。理论上,我可以计算每条线的 LinearGradientBrush 的角度(或开始/结束位置),并在线的点发生变化时更新它,但这并不理想,并且对于线数而言是一项昂贵的操作我打算画画。
RadialGradientBrush 似乎也没有帮助。
In WPF, is there a way to draw a line (in any orientation) that blends from one colour to another?
For example, I want to draw a line from point A to point B, where A is Red and B is Black. The line could be vertical, horizontal, or any orientation.
I have tried using a LinearGradientBrush, but this requires you to set an angle or Start/End positions. This won't work for me as I need to be able to draw the line at any two points in any orientation and still get it to blend. I could in theory compute the angle (or Start/End positions) for the LinearGradientBrush for each line and update it when ever the points of the line changes, but this wouldn't be ideal and would be an expensive operation for the number of lines I plan on drawing.
RadialGradientBrush also doesn't seem to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论
Grid
元素的宽度
如何,以下LinearGradientBrush
都会从红色“混合”为黑色:This following
LinearGradientBrush
"blends" from red to black regardless of theWidth
of theGrid
element: