发布时间:2024-05-16 14:01:53来源:本站阅读(1050)
使用 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
2451
1842
1842
1917
1271
4862
1848
2217
1217
1768
10863
6571
6136
5690
5201
4862
4159
3985
3929
3840