c# GDI+2D绘图

2021-05-27 22:02

阅读:648

标签:cli   nbsp   tpi   from   bmp   ext   button   ++   tar   

一、基础

GDI+步骤:

1.生成画布

2.生成画笔,包括颜色

3.开始画

 

private void Form1_Paint(object sender, PaintEventArgs e)
            {
                //创建画布,注意this
                Graphics g = this.CreateGraphics();
                //创建画笔,3种颜色方式
                Pen mp = new Pen(Color.Red, 10f); //10f宽度控制
                Pen np = new Pen(Color.FromArgb(255, 255, 255));
                Pen my = new Pen(Brushes.Black);
                //设置绘图开始和结束坐标
                Point pt1 = new Point(200, 200);
                Point pt2 = new Point(800, 800);
                //绘制直线
                g.DrawLine(mp, pt1, pt2);
                //绘制矩形
                Rectangle rec = new Rectangle(pt1, new Size(200, 500));//pt1为左上角坐标
                g.DrawRectangle(mp, rec);
                //绘制扇形
                g.DrawPie(mp, rec, 60, 60);
                //绘制字符串
                g.DrawString("c#是世界上最好的语言", new Font("宋体", 20, FontStyle.Underline), Brushes.Black, pt2);
                //定义单色画笔,画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径,此类不能被继承
                Brush solid = new SolidBrush(Color.Black);

            }

 

  

 

二、验证码更换

技术图片

 

  private void button1_Click(object sender, EventArgs e)
        {
            //生成bitmap画布
            Bitmap bmp = new Bitmap(150, 50);
            Graphics g = Graphics.FromImage(bmp);
            pictureBox1.Image = bmp;


            //生成随机验证码
            Random r = new Random();
            string str = null;
            for (int i = 0; i 

  

 

c# GDI+2D绘图

标签:cli   nbsp   tpi   from   bmp   ext   button   ++   tar   

原文地址:https://www.cnblogs.com/yaoyue68/p/14791063.html


评论


亲,登录后才可以留言!