This commit is contained in:
parent
60749eec1c
commit
5e7026dfc7
|
|
@ -178,11 +178,17 @@ public class CaptchaService : ICaptchaService
|
|||
/// </summary>
|
||||
private void DrawCaptchaText(SKCanvas canvas, string code)
|
||||
{
|
||||
using var paint = new SKPaint
|
||||
// 使用默认字体,避免服务器上缺少特定字体导致文字不显示
|
||||
var typeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold)
|
||||
?? SKTypeface.FromFamilyName("Microsoft YaHei", SKFontStyle.Bold)
|
||||
?? SKTypeface.FromFamilyName(null, SKFontStyle.Bold)
|
||||
?? SKTypeface.Default;
|
||||
|
||||
using var font = new SKFont(typeface, 26);
|
||||
using var paint = new SKPaint(font)
|
||||
{
|
||||
IsAntialias = true,
|
||||
TextSize = 24,
|
||||
Typeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold)
|
||||
Color = SKColors.Black
|
||||
};
|
||||
|
||||
var charWidth = (ImageWidth - 20) / code.Length;
|
||||
|
|
@ -192,16 +198,16 @@ public class CaptchaService : ICaptchaService
|
|||
{
|
||||
// 每个字符使用不同的深色
|
||||
paint.Color = new SKColor(
|
||||
(byte)_random.Next(0, 100),
|
||||
(byte)_random.Next(0, 100),
|
||||
(byte)_random.Next(0, 100)
|
||||
(byte)_random.Next(0, 80),
|
||||
(byte)_random.Next(0, 80),
|
||||
(byte)_random.Next(0, 80)
|
||||
);
|
||||
|
||||
// 随机Y位置(垂直偏移)
|
||||
var y = _random.Next(25, 35);
|
||||
var y = _random.Next(26, 34);
|
||||
|
||||
// 绘制字符
|
||||
canvas.DrawText(code[i].ToString(), startX + i * charWidth, y, paint);
|
||||
canvas.DrawText(code[i].ToString(), startX + i * charWidth, y, font, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 898 KiB |
Loading…
Reference in New Issue
Block a user