繁体   English   中英

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

[英]How to use custom fonts in 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;

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

// 此解决方案在 Mat 图像上绘制测试

{   
    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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM