问题
I need to draw on canvas using a few brush patterns like "Paint" in Windows OS. I need "oil brush" and "pastel". As I understand, it's possible via VisualBrush.Visual (Canvas with vector paths).
<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,0,10,10"
ViewportUnits="Absolute" Viewbox="0,0,10,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,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,0"/>
<Slider x:Name="brushSizeSlider" HorizontalAlignment="Left" Margin="242,203,0,0" VerticalAlignment="Top" Width="237" Maximum="100"/>
<Label Content="Прозрачность цвета кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="179" Margin="0,176,0,0"/>
<Slider x:Name="transparencySlider" HorizontalAlignment="Left" Margin="0,203,0,0" VerticalAlignment="Top" Width="237" Maximum="255"/>
<Label Content="Стиль кисти:" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="103" Margin="242,0,0,0"/>
<RadioButton x:Name="normalBrush_rb" Content="Обычная кисть" HorizontalAlignment="Left" Margin="242,27,0,0" VerticalAlignment="Top" IsChecked="True"/>
<RadioButton x:Name="oilBrush_rb" Content="Кисть для масла" HorizontalAlignment="Left" Margin="242,77,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="pastelBrush_rb" Content="Пастель" HorizontalAlignment="Left" Margin="242,127,0,0" VerticalAlignment="Top"/>
<InkCanvas x:Name="normalBrush_ink"
Background="White"
HorizontalAlignment="Left" Height="30" Margin="242,42,0,0" VerticalAlignment="Top" Width="248">
</InkCanvas>
<InkCanvas x:Name="oilBrush_ink"
Background="White"
HorizontalAlignment="Left" Height="30" Margin="242,92,0,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,0" VerticalAlignment="Top" Width="248"/>
</Grid>
</UserControl>
In my app, I need to draw line on canvas with pattern (sample for user) and to draw, using this pattern, by mouse.
Can you help me with drawing, using brush pattern (step-by-step) in xaml and|or programmatically? It can be vector in xaml or image file using.
Brush pattern (.eps)
Brush pattern (.svg)
Source link of brush
Brush pattern (.xaml)
Now, I draw in xaml, using Brush pattern, but this is not oil brush (like in default paint app):
来源:https://stackoverflow.com/questions/58694139/brush-pattern-in-c-sharp-wpf-xaml-vector