Skip to content

Commit

Permalink
Merge pull request #1 from FarokhCode/master
Browse files Browse the repository at this point in the history
Adding more distortion
  • Loading branch information
arsanjani authored Jul 17, 2023
2 parents e7aade1 + 362454c commit 98834e8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion EasyCaptcha/Service/CaptchaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,17 @@ public byte[] CreateCAPTCHAImage(string text, string backgroundColor, string for
SolidBrush objSolidBrushColor = new SolidBrush(GetColor(foreColor));
objGraphics.FillPath(objSolidBrushColor, objGraphicsPath);
#region Distortion

//this code add ten random line in captcha image
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
// calculate line start and end point here using the Random class:
int x0 = rnd.Next(0, width);
int y0 = rnd.Next(0, height);
int x1 = rnd.Next(0, width);
int y1 = rnd.Next(0, height);
objGraphics.DrawLine(Pens.Gray, x0, y0, x1, x1);
}
double distort = new Random().Next(3, 6) * (new Random().Next(3) == 1 ? 1 : -1);
using (Bitmap copy = (Bitmap)objBitmap.Clone())
{
Expand Down

0 comments on commit 98834e8

Please sign in to comment.