c#,验证码,变形

来源:百度知道 编辑:UC知道 时间:2024/06/11 02:04:38
只要变形的部分.不要随即,不要噪点.
应该不难吧 ,代码量应该不多.尽量解释清楚点
我说的是生成网页上的验证码图片

这个用gdi+做并不难,先生成一个没变形的图片image1,
然后在建立一个image2,把image1的图像按像素循环一行一行“挪”到image2图像里,挪的时候设置偏移量就可以了,

代码:
Image image1 = new Bitmap(100, 50);
Image image2 = new Bitmap(100, 50);

Graphics g1 = Graphics.FromImage(image1);
Graphics g2 = Graphics.FromImage(image2);

g1.Clear(Color.Black);
g1.DrawString("ABCD", new Font("宋体", 30), new SolidBrush(Color.White), new PointF(0, 0));

g2.Clear(Color.Black);
for (int i = 0; i < image1.Height; i++)
{
double x = Math.Sin((double)i/2d) * 3d;

Rectangle srcRect = new Rectangle(0, i, 100, 1);
Rectangle descRect = new Rectangle((int)x, i, 100, 1);

g2.DrawImage(image1, descRect, srcRect, GraphicsUnit.Pixel);
}

pictureBox1.Image = imag