c# draw Chinese characters on the picture

To draw characters onto an image, you can use the following steps with C# and the OpenCV library:

Import the required namespaces:

csharpCopy Code

using Emgu.CV;

using Emgu.CV.Structure;

Load the image and create a blank image:



Image<Bgr, byte> image = new Image<Bgr, byte>("your_image_path.jpg");

Image<Bgr, byte> result = image.CopyBlank();

定义字体、颜色和文本内容:

csharpCopy Code

MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);

Bgr color = new Bgr(Color.Red); // 字体颜色

string text = "Hello World"; // 要写的文本内容

在空白图像上绘制文本:

csharpCopy Code

result.Draw(text, ref font, new Point(10, 20), color);

这里,new Point(10, 20)是文本的起始坐标。

显示或保存结果图像:

csharpCopy Code

result.Save("output_image.jpg");

result.Show();

完整的代码示例:

csharpCopy Code

using Emgu.CV;

using Emgu.CV.Structure;

using System.Drawing;



class Program

{

    static void Main(string[] args)

    {

        Image<Bgr, byte> image = new Image<Bgr, byte>("your_image_path.jpg");

        Image<Bgr, byte> result = image.CopyBlank();



        MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);

        Bgr color = new Bgr(Color.Red);

        string text = "Hello World";



        result.Draw(text, ref font, new Point(10, 20), color);



        result.Save("output_image.jpg");

        result.Show();

    }

}

Replace "your_image_path.jpg" in the above code with the actual path to the image file you want to use, and adjust the text and draw parameters to your desired values. Then compile and run the code and you'll get a plot with plotted text

Guess you like

Origin blog.csdn.net/sxmsxmsmxm/article/details/131707058