登录
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
18631081161 2026-03-26 20:24:45 +08:00
parent 60749eec1c
commit 5e7026dfc7
2 changed files with 14 additions and 8 deletions

View File

@ -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