矩形渐变填充

发布于 2024-12-26 07:46:19 字数 315 浏览 2 评论 0原文

我目前正在寻求实现有点像 http://pjnicholson.com/ 中的矩形的渐变效果Fireworks/fillgradients.htm

rectangle fill

如果我妥协一点我可以使用 RadialGradientBrush 接近此...但是有没有(不太痛苦)的方法来实现矩形效果?

I'm currently looking to achieve a gradient effect a bit like the rectangle in http://pjnicholson.com/Fireworks/fillgradients.htm

rectangle fill

If I compromise a little I can get close to this using RadialGradientBrush... but is there any (not too painful) way to achieve the rectangular effect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

歌入人心 2025-01-02 07:46:19

请改用 ImageBrush 并使用此图像(或使用某些图像编辑器生成的类似图像)作为矩形的背景。

Use an ImageBrush instead and use this image (or a similar image generated using some image editor) for the background of your rectangle.

秉烛思 2025-01-02 07:46:19

我和一位同事提出的一个解决方案是派生一个新面板,该面板使用 WriteableBitmap 作为其背景源。

该面板将为您提供制作 WriteableBitmap 所需的尺寸。使用任何你想要的算法,你都可以适当地填充它。在我们的例子中,我们需要径向或锥形渐变,但同样的概念也适用。

此外,您可以在新控件上创建多个属性来指定渐变的颜色。我们根据需要调整了 LinearGradientBrush,但如果您只使用两种颜色,简单的属性可能就足够了。

我手边没有代码,但会尝试找到它并稍后发布更新。但以上内容应该能让你继续下去。

One solution a colleague and I came with was to derive a new Panel that used a WriteableBitmap as the source for its background.

The panel will give you the dimensions you need to make your WriteableBitmap. Using whatever algorithm you want you can fill it appropriately. In our case, we needed a radial or cone gradient, but the same concept applies.

Additionally, you can create several properties on your new control to specify the colors for the gradient. We adapted a LinearGradientBrush for our needs, but if you're working on just two colors, simple properties may suffice.

I don't have the code handy but will try to find it and post an update later. But the above should get you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文