c# GDI绘制简单的艺术字

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;


namespace yishuzi
{
    public partial class Form1 : Form
    {
        //画布
        private Bitmap bu;
        //画笔
        private Graphics pen;
        //字体
        private Font f;
        //刷子 线性渐变
        private LinearGradientBrush b;
        //点
        private Point p;
        public Form1()
        {
            InitializeComponent();
            //适合
            bu = new Bitmap(this.pbox.Width,this.pbox.Height);
            //透明
            //bu.MakeTransparent();
            pen = Graphics.FromImage(bu);


            //看看有多少种字体 哪个好看
            //FontDialog a=new FontDialog();
            //a.ShowDialog();


            //设置字体  大小  样式加粗+倾斜
            f = new Font("@方正舒体", 60, FontStyle.Bold | FontStyle.Italic);
            //设置刷子
            b = new LinearGradientBrush(new Point(0, 0), new Point(0, 100), Color.Red, Color.Yellow);
        }
        private void huatu()
        {
            //得到输入的字符
            string s = this.tbox.Text;
            if (s.Length == 0)
                return;
            int n = s.Length;
            for (int i = 0; i < n; i++)
            {
                //设置每个字符的位置 占70   字体大小是60
                p = new Point(70 * i, 0);
                //字符string  字体font 刷子brush 坐标point
                pen.DrawString(s[i].ToString(), f, b, p);
            }
        }
        /// <summary>
        /// 显示随输入改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbox_TextChanged(object sender, EventArgs e)
        {
            //重绘
            pen.Clear(Color.White);
            huatu();
            pbox.Image = bu;
        }


        /// <summary>
        /// 存储图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //存储图片
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "(*.ico)|*.ico|(*.png)|*.png";
            if (save.ShowDialog() == DialogResult.OK)
            {
                bu.Save(save.FileName);
            }
        }
    }
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

大米粥哥哥

感谢认可!

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

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

打赏作者

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

抵扣说明:

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

余额充值