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 月 ...
随机推荐
- JAVA 基础编程练习题16 【程序 16 输入 9*9 表】
16 [程序 16 输入 9*9 表] 题目:输出 9*9 口诀. 程序分析:分行与列考虑,共 9 行 9 列,i 控制行,j 控制列. package cskaoyan; public class ...
- Tanimoto Coefficient
Tanimoto Coefficient The Tanimoto coefficient between two points, a and b, with k dimensions is calc ...
- vue中自定义指令的使用
原文地址 vue中除了内置的指令(v-show,v-model)还允许我们自定义指令 想要创建自定义指令,就要注册指令(以输入框获取焦点为例) 一.注册全局指令: // 注册一个全局自定义指令 `v- ...
- Day04:异常处理(二) / 多线程基础
多线程 线程是什么? 一个线程是线程一个顺序执行流. 同类的多个线程共享一块内存空间和一组系统资源,线程本身有一个供程序执行时的栈堆.线程在切换时负荷小,因此,线程也被称为轻负荷进程.一个进程中可以包 ...
- 禁止crontab -r清空定时任务列表误操作
关于crontab 1.附件cron.sh放/usr/bin目录下面 2.在/etc/bashrc文件末尾添加 alias crontab='/usr/bin/cron.sh' 或者在当前root用户 ...
- centos7修复grub2
GRUB :“the Grand Unified Bootloader ”引导加载程序 1.主要配置文件 #/boot/grub2/grub.cfg #rm -rf /boot/grub2/grub ...
- 图表:WebChartControl
#region 画统计图 /// <summary> /// 画统计图 /// </summary> private void LoadWebChartControl() { ...
- 关于MYSQL使用过程中的一些错误总结
一,java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 导致这个问题有很多种情况,我暂时遇到的是:未在lib下导入jar包. 这个链接是各个 ...
- 2019牛客暑期多校训练营(第八场)-A All-one Matrices (单调栈+前缀和)
题目链接:https://ac.nowcoder.com/acm/contest/888/A 题意:给n×m的01矩阵,求出其中全为1的矩阵个数(不被其它全1矩阵包括). 思路:和第二场多校的次大子矩 ...
- Centos7 + nginx 托管 Django 项目
使用nginx托管django服务的原理 使用uwsgi开启django服务(通过配置文件启动) 防火墙关闭uwsgi端口(uwsgi的websocket一定要使用127.0.0.1的方式配置)) 编 ...