如何在 emgucv 中使用自定义字体
本文关键字:自定义 字体 emgucv | 更新日期: 2023-09-27 18:34:31
我知道如何在Emgu CV中的图像上绘制文本:
CvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX_SMALL, 1, 1);
image.Draw("something", ref f, new Point(0, 0), new Rgb(0, 0, 0));
但我不知道如何使用其他字体代替CV_FONT_HARSHEY*
更新:
这是完整的解决方案:
var b = image.Bitmap;
Graphics g = Graphics.FromImage(b);
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
PointF drawPoint = new PointF(0,0);
g.DrawString("something,", drawFont, drawBrush, drawPoint);
/// after drawing etc.
image.Bitmap = b;
您可以在PrivateFontCollection
中添加TTF文件
// 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
var foo = new PrivateFontCollection();
// Provide the path to the font on the filesystem
foo.AddFontFile("...");
var myCustomFont = new Font((FontFamily)foo.Families[0], 36f);
然后你画这样的图像:
image.Draw("something", myCustomFont, new Point(0, 0), new Rgb(0, 0, 0));
或者你可以使用myCustomFont的方法:Graphics.DrawString
//此解决方案在垫子图像上绘制测试
{
var b = myMat.ToBitmap();
Graphics g = Graphics.FromImage(b);
Font drawMFont = new Font("Calibri", 8, FontStyle.Bold);
SolidBrush drawMBrush = new SolidBrush(Color.DarkCyan);
PointF drawMPoint = new PointF(1, 4);
g.DrawString("Hello",drawMFont,drawMBrush, drawMPoint);
}