C#WPF中的画笔图案(XAML-矢量图)

我需要在Windows OS中使用几种画笔模式(例如“ Paint”)在画布上进行绘制。 我需要“油刷”和“粉彩”。 据我了解,可以通过VisualBrush.Visual(带有矢量路径的画布)来实现。

<UserControl x:Class="DrawingToolbar.DTBrushParamsContainer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:DrawingToolbar"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="395" d:DesignWidth="500">

    <UserControl.Resources>
        <VisualBrush 
            x:Key="OilBrush" 
            TileMode="Tile" Viewport="0,10,10" 
            ViewportUnits="Absolute" Viewbox="0,10"    
            ViewboxUnits="Absolute">
            <VisualBrush.Visual>
                <Canvas Width="495.9968" Height="66.6656" ClipToBounds="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

                </Canvas>
            </VisualBrush.Visual>
        </VisualBrush>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="55" />
        </Grid.RowDefinitions>


        <xctk:ColorCanvas x:Name="colorCanvas" Grid.Row="0" 
                          Background="Transparent"
                          Height="145" Width="237"
                          UsingAlphaChannel="False" Margin="0,27,0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
        <Label Content="Цвет кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="82"/>
        <Label Content="Толщина кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="103" Margin="242,176,0"/>
        <Slider x:Name="brushSizeSlider" HorizontalAlignment="Left" Margin="242,203,0" VerticalAlignment="Top" Width="237" Maximum="100"/>
        <Label Content="Прозрачность цвета кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="179" Margin="0,0"/>
        <Slider x:Name="transparencySlider" HorizontalAlignment="Left" Margin="0,0" VerticalAlignment="Top" Width="237" Maximum="255"/>
        <Label Content="Стиль кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="103" Margin="242,0"/>
        <RadioButton x:Name="normalBrush_rb" Content="Обычная кисть" HorizontalAlignment="Left" Margin="242,0" VerticalAlignment="Top" IsChecked="True"/>
        <RadioButton x:Name="oilBrush_rb" Content="Кисть для масла" HorizontalAlignment="Left" Margin="242,77,0" VerticalAlignment="Top"/>
        <RadioButton x:Name="pastelBrush_rb" Content="Пастель" HorizontalAlignment="Left" Margin="242,127,0" VerticalAlignment="Top"/>

        <InkCanvas x:Name="normalBrush_ink" 
            Background="White"
            HorizontalAlignment="Left" Height="30" Margin="242,42,0" VerticalAlignment="Top" Width="248">

        </InkCanvas>

        <InkCanvas x:Name="oilBrush_ink" 
            Background="White"
            HorizontalAlignment="Left" Height="30" Margin="242,92,0" VerticalAlignment="Top" Width="248">

            <Line X1="10" X2="100" Y1="15" Y2="15" Visibility="Visible" StrokeThickness="5" Stroke="{StaticResource OilBrush}">
            </Line>

        </InkCanvas>

        <InkCanvas x:Name="pastelBrush_ink" 
            Background="White"
            HorizontalAlignment="Left" Height="30" Margin="242,142,0" VerticalAlignment="Top" Width="248"/>


    </Grid>
</UserControl>

在我的应用中,我需要在画布上绘制带有图案的线(供用户使用的示例),并使用鼠标使用此图案进行绘制。

您能在xaml中和/或以编程方式使用画笔图案(逐步)来帮助我进行绘图吗?可以是xaml中的矢量,也可以是使用的图像文件。

Brush pattern (.eps)

Brush pattern (.svg)

Source link of brush

Brush pattern (.xaml)

现在,我使用“画笔”模式绘制xaml,但这不是油画笔(例如在默认的绘画应用程序中):

C#WPF中的画笔图案(XAML-矢量图)

akinschen 回答:C#WPF中的画笔图案(XAML-矢量图)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3166525.html

大家都在问