验证码的制作

 

1、form 的 paint事件:(在load里绘制无效)
Graphics 不能直接使用new来创建需要和一个设备关联
Graphics g=this.CreateGraphics();
g.DrawLine(Pens.Red,0,0,100,100);
或者在Paint事件里还可以:e.Graphics.DrawLine(Pens.Black,100,0,100,100);

在图像上绘制:
if (this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
            {
                Image img = Image.FromFile(this.openFileDialog1.FileName);
                Graphics g = Graphics.FromImage(img);
                Color c = Color.FromArgb(133,30,40,60);
                Pen p = new Pen(c, 10);
                g.DrawEllipse(p, 0, 0, 60, 80);//椭圆
                //g.DrawEllipse(Pens.Blue, 0, 0, 60, 80);//椭圆

                Color c1 = Color.FromArgb(200,30,40,60);
                Pen p1 = new Pen(c1,20);
                g.DrawEllipse(p1, 0, 0, 60, 80);//椭圆
                g.FillEllipse(Brushes.Green, 20, 20, 50, 40);//填充颜色
                this.pictureBox1.Image = img;
            }

画刷:
                //画刷的使用
                //Brush b = Brushes.Gray;
                //自己定义
                SolidBrush b = new SolidBrush(c1);
                //texturebrush纹理画刷
                TextureBrush tb = new TextureBrush(Image.FromFile("E:\\图片
\\1.jpg"));
                Pen pen = new Pen(tb);
                pen.Width = 20;
                g.DrawLine(pen,0,0,40,40);
                g.FillRectangle(b,50,50,20,20);
                this.pictureBox1.Image = img;

 

扇形、弧、图片水印:
                //  g.DrawPie(p1,0,0,40,40,90,270);//扇形
                TextureBrush tb = new TextureBrush(Image.FromFile("E:\\图片
\\1.jpg"));
                Image img1 = Image.FromFile("E:\\图片
\\1.jpg");
                // g.DrawPie(p1, 0, 0, 40, 40, 90, 270);//弧
                g.DrawString("HBSI",new Font("宋体",20),tb,0,0);//写字符串
                g.DrawImage(img1, img.Width - img1.Width, img.Height - img1.Height);
                img.Save("E:\\图片
\\2.jpg");
                this.pictureBox1.Image = img;

 

绘制验证码:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值