我怎样绘制"软QUOT;在WPF线(presumably使用一个LinearGradientBrush)? [英] How can I draw a "soft" line in WPF (presumably using a LinearGradientBrush)?

查看:195
本文介绍了我怎样绘制"软QUOT;在WPF线(presumably使用一个LinearGradientBrush)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制软边一条线,不管坡。

I'm trying to draw a line with soft edges, regardless of the slope.

这里的code我到目前为止有:

Here's the code I have so far:

<Line   HorizontalAlignment="Stretch" VerticalAlignment="Center"
        Stretch="Uniform" StrokeThickness="5" X1="0" Y1="0" X2="1" Y2="0">
    <Shape.Stroke>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="Transparent" Offset="0" />
            <GradientStop Color="Green" Offset="0.5" />
            <GradientStop Color="Transparent" Offset="1" />
        </LinearGradientBrush>
    </Shape.Stroke>
</Line>

这是有意义的我的,因为行是水平的,并且线性梯度是垂直的,与边缘是透明的,线的中间为绿色。

This makes sense to me, since the line is horizontal, and the linear gradient is vertical, with the edges being transparent and the middle of the line being solid green.

其结果是令人高兴:

放大,所以你可以看到渐变:

The result is pleasing:

Zoomed in so you can see the gradient:

然而,当线不再水平,梯度是根据线的边界矩形来计算的,而不是就行本身的几何形状。其结果是,代替梯度垂直于行被竖直阴影斜线,:

However, when the line is no longer horizontal, the gradient is calculated based on the line's bounding rectangle, rather than on the geometry of the line itself. The result is a slanted line that is shaded vertically, instead of the gradient being perpendicular to the line:

有谁知道WPF如何处理软边?我找不到对谷歌或MSDN什么,我知道有一种方法可以做到这一点somewhow ...

Does anyone know how WPF handles soft edges? I can't find anything on Google or MSDN, and I know there is a way to do this somewhow...

推荐答案

好了,我不知道这是否适用于您的情况,但你可以简单地旋转水平线使用LayoutTransform和梯度都会好起来的。

Well, I do not know if that is applicable to your scenario but you could simply rotate the horizontal line using LayoutTransform and the gradient will be okay.

<Line   HorizontalAlignment="Stretch" VerticalAlignment="Center"
    Stretch="Uniform" StrokeThickness="5" X1="0" Y1="0" X2="1" Y2="0">
<Shape.Stroke>
    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="Transparent" Offset="0" />
        <GradientStop Color="Green" Offset="0.5" />
        <GradientStop Color="Transparent" Offset="1" />
    </LinearGradientBrush>
</Shape.Stroke>
    <Line.LayoutTransform>
        <RotateTransform Angle="40"/>
    </Line.LayoutTransform>

这篇关于我怎样绘制&QUOT;软QUOT;在WPF线(presumably使用一个LinearGradientBrush)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆