如何在emgucv中使用自定义字体?

时间:2016-02-13 14:42:57

标签: c# emgucv

我知道如何在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;

1 个答案:

答案 0 :(得分:3)

您可以在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