◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
易尔译科技 致力于互联网高端应用软件以及自然语言处理项目研发。团队TM群:18653820 技术成长QQ群:13554183
扭曲图片(验证码)的较正处理C#代码
Post by 54admin, 2009-7-13, Views:在很多的验证码图片中,作者会刻意将图片中的文字“扭曲”一下,如下变成斜体。这样就会增加程序识别的难度。作为挂机程序的编写者,自然要反其道而行之,比较有效的一种方法是将“扭曲”的过程反过来校正一下,如图。这样处理,就比较容易分割了。
实现的代码如下:
1
private void button2_Click(object sender, EventArgs e)
2
{
3
Bitmap curBitmap = new Bitmap(pictureBox1.Image.Width,pictureBox1.Image.Height);
4
Graphics g = Graphics.FromImage(curBitmap);
5
Matrix X = new Matrix();
6
// X.Rotate(30);
7
X.Shear((float)0.16666666667, 0); // 2/12
8
g.Transform = X;
9
// Draw image
10
//Rectangle cloneRect = GetPicValidByValue(128); //Get Valid Pic Rectangle
11
Rectangle cloneRect = new Rectangle(6, 5, 40, 12);
12
Bitmap tmpBmp = ((Bitmap)pictureBox1.Image).Clone(cloneRect, pictureBox1.Image.PixelFormat);
13
g.DrawImage(tmpBmp,
14
new Rectangle(6, 5, 40, 12),
15
0, 0, tmpBmp.Width,
16
tmpBmp.Height,
17
GraphicsUnit.Pixel);
private void button2_Click(object sender, EventArgs e)2
{3
Bitmap curBitmap = new Bitmap(pictureBox1.Image.Width,pictureBox1.Image.Height);4
Graphics g = Graphics.FromImage(curBitmap);5
Matrix X = new Matrix();6
// X.Rotate(30);7
X.Shear((float)0.16666666667, 0); // 2/128
g.Transform = X;9
// Draw image10
//Rectangle cloneRect = GetPicValidByValue(128); //Get Valid Pic Rectangle11
Rectangle cloneRect = new Rectangle(6, 5, 40, 12);12
Bitmap tmpBmp = ((Bitmap)pictureBox1.Image).Clone(cloneRect, pictureBox1.Image.PixelFormat);13
g.DrawImage(tmpBmp,14
new Rectangle(6, 5, 40, 12),15
0, 0, tmpBmp.Width,16
tmpBmp.Height,17
GraphicsUnit.Pixel);19
pictureBox2.Image=curBitmap ;
20
}
21
Tags: 扭曲图片较正
分类:项目知识 | 评论:1 | 引用:0 | 点击这里获取该日志的TrackBack引用地址
