发布时间:2024-05-16 14:01:53来源:本站阅读(1054)
使用 SkiaSharp(通知中提到的第一个替代方案)进行直接替换。
它没有许可证限制。
using (SKCanvas canvas = new SKCanvas(bitmap))
{
using (SKPaint textPaint = new SKPaint())
{
textPaint.Color = SKColors.Black;
textPaint.IsAntialias = true;
textPaint.TextSize = 30;
// 将验证码文本居中绘制到图片上
float textWidth = textPaint.MeasureText(chkCode);
float x = (codeW - textWidth) / 2;
float y = (codeH - textPaint.TextSize) / 2;
canvas.DrawText(chkCode, x, y, textPaint);
}
} 返回byte[]
using (SKImage img = SKImage.FromBitmap(bitmap))
{
using (SKData p = img.Encode(SKEncodedImageFormat.Png, 100))
{
return p.ToArray();
}
}
关键字: .NET 8
2263
1278
1352
1760
1919
1294
1365
1291
1914
1350
10878
6574
6143
5696
5206
4868
4165
3988
3936
3844