WPF中GDI+图形图像的绘制:(二)绘制文本——字体描边、渐变、图片叠加

该篇博客详细介绍了如何在WPF中利用GDI+进行文本的高级绘制,包括动态设置字体描边、应用渐变效果以及实现图片叠加。通过示例代码和效果展示,作者逐步讲解了窗体xaml的配置、FontItem类的扩展以及相关事件的处理,帮助读者掌握WPF中图形图像的绘制技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先放效果:

1、在上一节WPF中GDI+图形图像的绘制:(一)绘制文本——动态设置字体、大小、颜色 的基础上继续添加字体描边、渐变和图片叠加相关控件,窗体xaml如下:

<Window x:Class="DrawDemo.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:local="clr-namespace:DrawDemo"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
        Title="GDI+绘制" Height="768" Width="1280" Loaded="Window_Loaded">
    <Grid Background="#f0f0f0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"></ColumnDefinition>
            <ColumnDefinition ></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="380"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <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>
        </Canvas>
        <GroupBox Grid.Row="0" 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 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>
                <TextBox x:Name="tbFontText" Grid.Row="0" Grid.Column="1" Height="26" Width="180" VerticalAlignment="Center" HorizontalAlignment="Left" TextChanged="tbFontText_TextChanged"></TextBox>
                <Label Grid.Row="1" Grid.Column="0" Content="选择字体" VerticalAlignment="Center" HorizontalAlignment="Left"></Label>
               
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RunnerDNA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值