发布时间:2024-05-16 14:01:53来源:本站阅读(523)
使用 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
1814
4436
901
1199
1763
1582
1042
1608
1492
984
9911
6137
5682
5254
4722
4436
3603
3487
3485
3394