wpf 在SkiaSharp中,线的宽度呈现不同

yebdmbv4  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(164)

我在WPF中使用SkiaSharp绘制两条线,但是线的宽度似乎不同-垂直线似乎更粗。发生这种情况有什么原因吗?我使用的SkiaSharp版本是2.80.1。

<Window
    x:Class="SkiaSharpSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:skia="clr-namespace:SkiaSharp.Views.WPF;assembly=SkiaSharp.Views.WPF"
    Title="SkiaSharp"
    Width="525"
    Height="350"
    mc:Ignorable="d">
    <Grid>
        <skia:SKElement PaintSurface="OnPaintSurface" />
    </Grid>
</Window>

private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
    SKCanvas canvas = e.Surface.Canvas;

    // make sure the canvas is blank
    canvas.Clear(SKColors.White);

    var paint = new SKPaint
    {
        Color = new SKColor(255, 0, 0, 255),
        IsAntialias = true,
        Style = SKPaintStyle.Stroke,
        StrokeWidth = 0
    };

    canvas.DrawLine(100, 0, 100, 100, paint);
    canvas.DrawLine(100, 0, 200, 100, paint);
}
kx7yvsdv

kx7yvsdv1#

尝试将垂直线的抗锯齿设置为False。我还没有测试过,所以我不知道它是否有效。

相关问题