简体   繁体   中英

Draw / Write on an image more than one line - EmguCV (OpenCV) does not recognize new line char

I'm trying to Draw a string that have more than one line at a EmguCV (OpenCV C# wraper) Image. But it seams that EmguCV doesn't recognize the new line "\\r\\n" characters.

How can achieve that? Alternatively, how can I get the text height, so I can set the location for the next string manually?

StringBuilder imageComments = new StringBuilder();
imageComments.AppendLine("Camera status");
imageComments.AppendLine("Shutter: " + shutter);
Emgu.CV.Image<Gray, Byte> img = new Emgu.CV.Image<Gray, byte>(bmp);
Point location = new Point(30, 30);
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 0.3f, 0.3f);
Gray color = new Gray(255);
img.Draw(imageComments.ToString(), ref font, location, color);

You can always make your own function that parses the paragraph into individual lines and then produce the y-displacement needed for each row. If I remember correctly, the default font size is 16 pixels.

void myDrawMultiLineText(string InputParagraph, Point Origin)
{
vector<string> LinesOfText = myParse(InputParagraph,"\n");
for (int i=0;i<LinesOfText.size(); ++i)
    DrawText(CurrentLine[i], Origin.x, Origin.y + i*16);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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