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 月 ...
随机推荐
- 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-2.中大型公司里面项目开发流程讲解
笔记 2.中大型公司里面项目开发流程讲解 简介:讲解一个项目如何从零到上线,经历过怎样的步骤和流程 1.一个中大型项目的开发流程,从需求调研到项目上线 ...
- DBUtil连接数据库
1. SQL server连接: 数据库不同架包就不同 SQL server 使用的架包是(sqljdbc4.jar) 2. Mysql (MariaDB同理) SQL server 使用的架包是(m ...
- [ML] Load and preview large scale data
Ref: [Feature] Preprocessing tutorial 主要是 “无量纲化” 之前的部分. 加载数据 一.大数据源 http://archive.ics.uci.edu/ml/ht ...
- python实现在目录中查找指定文件的方法
python实现在目录中查找指定文件的方法 本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 代码如下: import os from ...
- Daily in Ipin
Friday, October 23 1. [道高一尺,墙高一丈:互联网封锁是如何升级的] Monday, October 12 1. 晕死,忘了ubuntu的登录密码,鼓捣了半个小时,终于成功进入系 ...
- plsql 查询中文乱码问题
记录一下解决中文乱码 设置环境变量 set path=E:\app\Administrator\product\instantclient_10_2 set TNS_ADMIN=E:\app\Admi ...
- 前端面试经典题之apply与call的比较
在讲apply和call之前,我们需要先清楚在js中,this指向的是什么. 大家可以参考一下阮一峰老师写的关于JavaScript中this的原理讲解文章:http://www.ruanyifeng ...
- Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III)
Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III) 股票问题: 121. 买卖股票的最佳时机 122 ...
- Python全栈开发之7、面向对象编程进阶-类属性和方法、异常处理和反射
一.类的属性 1.@property属性 作用就是通过@property把一个方法变成一个静态属性 class Room: def __init__(self,name,length,width,he ...
- 获得http请求的RequestID
firefox: F12---network---响应, 请求一个页面: