发布时间:2024-05-16 14:01:53来源:本站阅读(729)
使用 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
1859
1762
1777
1962
1679
2139
1792
1595
1746
1706
10279
6297
5837
5410
4908
4609
3825
3685
3645
3561