GDI+ 绘图教程 验证码
使用的 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+ 绘图教程 验证码的更多相关文章
- VB6 GDI+ 入门教程[5] 基础绘图小结
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[5] 基础绘图小结 2009 年 6 月 18 日 4条 ...
- VB6 GDI+ 入门教程[1] GDI+介绍
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[1] GDI+介绍 2009 年 6 月 18 日 17 ...
- VB6 GDI+ 入门教程[2] GDI+初始化
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[2] GDI+初始化 2009 年 6 月 18 日 7 ...
- VB6 GDI+ 入门教程[4] 文字绘制
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[4] 文字绘制 2009 年 6 月 18 日 7条评论 ...
- VB6 GDI+ 入门教程[6] 图片
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[6] 图片 2009 年 6 月 19 日 15条评论 ...
- 如何用GDI+画个验证码
如何使用GDI+来制作一个随机的验证码 绘制验证码之前先要引用 using System.Drawing; using System.Drawing.Drawing2D; 首先,先写一个方法来取得验证 ...
- MFC GDI绘图基础
一.关于GDI的基本概念 什么是GDI? Windows绘图的实质就是利用Windows提供的图形设备接口GDI(Graphics Device Interface)将图形绘制在显示器上. 在Wind ...
- VB6 GDI+ 入门教程[3] 笔、刷子、矩形、椭圆绘制
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[3] 笔.刷子.矩形.椭圆绘制 2009 年 6 月 1 ...
- VB6 GDI+ 入门教程[7] Graphics 其他内容
http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[7] Graphics 其他内容 2009 年 9 月 ...
随机推荐
- Linux上MongoDB一些设置
MongoDB启动停止方法 官网安装介绍中依然有启动停止的方式 1 启动 sudo service mongod start 2 停止 sudo service mongod stop 3 重启 su ...
- mysql 高性能日记之索引(持续更新)
本文仅限于自己读写的笔记,需要具有一定 mysql(inodb,myisam 引擎)基础的高端玩家,不感兴趣的玩家们就不用在意了 Inodb 引擎 1,每个新建索引,都需要考虑清楚看是否是必须的,很多 ...
- Android中为TextView增加自定义的HTML标签
Android中的TextView,本身就支持部分的Html格式标签.这其中包括常用的字体大小颜色设置,文本链接等.使用起来也比较方便,只需要使用Html类转换一下即可.比如: textView.se ...
- ELK故障处理,不知道成功否
上周?还是上上周??发现ELK的数据都没有更新了,考虑到这个系统目前不重要,就没有理会.今日再次登陆,发现没有数据更新了!!! system overview 没有主机,没有数据. 登陆系统检查状态, ...
- Golang gRPC微服务01: 介绍
gRPC 是什么 gRPC是goole开源的一个RPC框架和库,支持多语言之间的通信.底层通信采用的是 HTTP2 协议.gRPC在设计上使用了 ProtoBuf 这种接口描述语言.这种IDL语言可以 ...
- postman生成格式化时间
方法一: var moment = require('moment'); var data = moment().format(" YYYYMMDDHHmmss"); consol ...
- Unity3D热更新之LuaFramework篇[05]--Lua脚本调用c#以及如何在Lua中使用Dotween
在上一篇文章 Unity3D热更新之LuaFramework篇[04]--自定义UI监听方法 中,我对LuaBehaviour脚本进行了扩展,添加了两个新的UI监听方法,也提到最好能单写一个脚本处理此 ...
- 网站后台扫描工具dirbuster、御剑的用法
dirbuster DirBuster是Owasp(Open Web Application Security Project )开发的一款专门用于探测网站目录和文件(包括隐藏文件)的工具.由于使用J ...
- PowerDesigner通过SQL语句生成PDM文件并将name和comment进行互相转换
本篇文章主要介绍了PowerDesigner通过SQL语句生成PDM文件并将name和comment进行互相转换 超详细过程(图文),具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.软件准备 软 ...
- sql中级语句
创建联结 select n_title,n_content,t_name,t_memo from nrc_news,nrc_type where nrc_news.t_id=nrc_type.t_id ...