使用的 C# winform

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDI_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 一根笔 绘制直线的对象 pen 颜色 Brush Brushes SolidBrush color  一张纸(图面) Graphics  两点 Point

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //创建GDI图面对象
            //Graphics g = new Graphics(); 没有定义构造函数
            //创对象
            // 1 在堆中开空间 2 在开辟的空间创对象 3 调用构造函数

            Graphics g = this.CreateGraphics();
            //创建画笔对象  画笔
            //1
            //Pen pen = new Pen(Brushes.Yellow);//Brush 点不出来 看复数
            //2 直接给笔上色
            Pen pen = new Pen(Color.Yellow);//
            //Pen pen = new Pen(new Brush(Color.Yellow));Brush 抽象类报错
            //创建两个点
            Point p1 = , );
            Point p2 = , );

            g.DrawLine(pen, p1, p2);
        }
        ;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            label1.Text = i.ToString();
            //创建GDI对象
            //Graphics g = new Graphics();
            //创对象
            // 1 在堆中开空间 2 在开辟的空间创对象 3 调用构造函数

            Graphics g = this.CreateGraphics();
            //创建画笔对象  画笔
            Pen pen = new Pen(Brushes.Yellow);// 复数形式 返回对象
            //创建两个点
            Point p1 = , );
            Point p2 = , );

            g.DrawLine(pen, p1, p2);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Yellow);
            Size si = , );
            Rectangle rec = , ), si); // 矩形对象
            g.DrawRectangle(pen, rec);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Blue);
            Size si = , );
            Rectangle rec = , ), si);
            g.DrawPie(pen, rec, , );//他要什么 我们就给什么
            //Draw 画  在图上绘制 Graphics 

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Font f = , FontStyle.Underline);
            g.DrawString(, ));
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDI_验证码
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //点击更换验证码
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //1 产生随机数
            Random r = new Random();
            string str = null;
            ; i < ; i++)
            {
                , );
                str += rNumber;
            }
            //MessageBox.Show(str);
            // 画一个图片 把文本放到图片里面去
            //创建GDI对象
            Bitmap bmp = , );//创建位图
            //位图 操作系统中 默认的图片类型 其实就是位图(.bmp)
            Graphics g = Graphics.FromImage(bmp); //对象从图片来 就是在图片上绘制

            // 画数字
            ; i < ; i++)
            {
                Point p = , );
                string[] fonts = { "宋体", "微软雅黑", "黑体", "隶书", "仿宋" };
                Color[] colors = { Color.Yellow, Color.Blue, Color.Red, Color.Black, Color.Green };
                g.DrawString(str[i].ToString(), , )], , FontStyle.Bold), , )]), p);
            }

            //画线
            ; i < ; i++)
            {//线必须在验证码图片里面
                Point p1 = , bmp.Width), r.Next(, bmp.Height));
                Point p2 = , bmp.Width), r.Next(, bmp.Height));
                g.DrawLine(new Pen(Brushes.Green), p1, p2);
            }
            //画点
            ; i < ; i++)
            {
                //创建点
                Point p = , bmp.Width), r.Next(, bmp.Height));
                bmp.SetPixel(p.X, p.Y, Color.Black);//再在图上画点
            }

            //将图片镶嵌到picturebox中
            pictureBox1.Image = bmp;
        }
    }
}

GDI+ 绘图教程 验证码的更多相关文章

  1. VB6 GDI+ 入门教程[5] 基础绘图小结

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[5] 基础绘图小结 2009 年 6 月 18 日 4条 ...

  2. VB6 GDI+ 入门教程[1] GDI+介绍

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[1] GDI+介绍 2009 年 6 月 18 日 17 ...

  3. VB6 GDI+ 入门教程[2] GDI+初始化

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[2] GDI+初始化 2009 年 6 月 18 日 7 ...

  4. VB6 GDI+ 入门教程[4] 文字绘制

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[4] 文字绘制 2009 年 6 月 18 日 7条评论 ...

  5. VB6 GDI+ 入门教程[6] 图片

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[6] 图片 2009 年 6 月 19 日 15条评论 ...

  6. 如何用GDI+画个验证码

    如何使用GDI+来制作一个随机的验证码 绘制验证码之前先要引用 using System.Drawing; using System.Drawing.Drawing2D; 首先,先写一个方法来取得验证 ...

  7. MFC GDI绘图基础

    一.关于GDI的基本概念 什么是GDI? Windows绘图的实质就是利用Windows提供的图形设备接口GDI(Graphics Device Interface)将图形绘制在显示器上. 在Wind ...

  8. VB6 GDI+ 入门教程[3] 笔、刷子、矩形、椭圆绘制

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[3] 笔.刷子.矩形.椭圆绘制 2009 年 6 月 1 ...

  9. VB6 GDI+ 入门教程[7] Graphics 其他内容

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[7] Graphics 其他内容 2009 年 9 月 ...

随机推荐

  1. CSS3动画相关属性详解

    本文转载于:<https://blog.csdn.net/lyznice/article/details/54575905> 一.2D效果属性 要使用这些属性,我们需要通过 transfo ...

  2. 跨平台编程相关技术资料及笔记.md

    目录 跨平台编程技术选型 ## 需求 最终选定的技术方案:uni-app 混合或跨平台编程相关资料 ## uni-app 官网 相关资料 个人笔记 个人经验 ## taro 官网 相关资料 ## Ch ...

  3. IDEA如何构建mybatis

    任何一个软件都要和数据库关联,软件需要的数据都存储在数据库中. 对于经常使用的数据库相关的代码就出现了很多冗余的代码,持久层框架也随之出现. 目前使用比较流程的持久层框架有hibernate和myba ...

  4. php+UEditor粘贴word

    最近公司做项目需要实现一个功能,在网页富文本编辑器中实现粘贴Word图文的功能. 我们在网站中使用的Web编辑器比较多,都是根据用户需求来选择的.目前还没有固定哪一个编辑器 有时候用的是UEditor ...

  5. Elasticsearch.Net API 图片汇总

  6. C2B电商三种主要模式的分析_数据分析师

    C2B电商三种主要模式的分析_数据分析师 在过去的一年中电商领域血雨腥风,尤其是天猫.京东.苏宁.当当.易讯等B2C电商打得不亦乐乎.而随着B2C领域竞争进入白热化阶段,C2B模式也在天猫" ...

  7. Kafka管理与监控——查看和重设消费者组位移

    kafka 0.11.0.0版本丰富了kafka-consumer-groups脚本的功能,用户可以直接使用该脚本很方便地为已有的consumer group重新设置位移. 前提必须consumer ...

  8. React Native细节知识点总结<二>

    1.关于React Native导出组件的export default和export的问题: 一个文件只能有一个export default,可以有多个export export class Temp ...

  9. centos7 忘记mysql root登录密码

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和 ...

  10. 九大内置对象 and HTTP略微的个人见解

    jsp 中九大内置对象: 请求对象:request      输出对象:out         响应对象:response      应用程序对象:application      会话对象:sess ...