Skip to content

Commit

Permalink
Добавлена возможность добавления пользовательского текста
Browse files Browse the repository at this point in the history
  • Loading branch information
Katy248 committed Oct 1, 2022
1 parent 7af92bf commit 59669bc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Captcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public Captcha(int length = 10)
answer = GenerateAnswer(length);
image = GenerateImage(200, 90 * length);
}
public Captcha(string captchaText)
{
answer = captchaText;
image = GenerateImage(200, 90 * captchaText.Length);
}
private readonly string answer;
private readonly Bitmap image;
private static Random random = new Random();
Expand All @@ -33,10 +38,10 @@ private Bitmap GenerateImage(int height, int width)
.DrawText(answer, Color.White)
.AddEffect((gr, x, y) =>
{
if (x % 5 == 0)
using (SolidBrush sb = new SolidBrush(RandomColor()))
using (Pen pen = new Pen(new SolidBrush(RandomColor())))
gr.DrawRectangle(pen, x, y, 2, 2);
if (x % 5 != 0) return;
using (SolidBrush sb = new SolidBrush(RandomColor()))
using (Pen pen = new Pen(new SolidBrush(RandomColor())))
gr.DrawRectangle(pen, x, y, 2, 2);
})
.Image();
}
Expand Down

0 comments on commit 59669bc

Please sign in to comment.