接下来介绍GDI+绘制图像的方法,这次主要实现的功能是图片黑白、浮雕、锐化的效果,效果图:
1、接着之前绘制字体的工程,首先在Canvas里再添加一个Image控件用来绘制图片;
<Canvas x:Name="mainCanvas" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Background="White" Width="960" Height="720" Margin="10,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ClipToBounds="True">
<Image x:Name="imgFont"></Image>
<Image x:Name="imgPic"></Image>
</Canvas>
2、在窗体里添加绘图的相关控制控件组;
<GroupBox Grid.Row="1" Grid.Column="1" Margin="10" Header="图像">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="选择图片" VerticalAlignment="Center" HorizontalAlignment="Left"></Label>
<Button x:Name="btnChooseImg" Grid.Row="0" Grid.Column="1" Content="选择" VerticalAlignment="Center" HorizontalAlignment="Left" Height="26" Width="80" Click="btnChooseImg_Click"></Button>
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
<Button x:Name="btnBlackAndWhite" Content="黑白" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Left" Height="26" Width="60" Click="btnBlackAndWhite_Click"></Button>
&