SVG:从 C# 测量一些文本的边界框 [英] SVG: measure the bounding box of some text from C#

查看:30
本文介绍了SVG:从 C# 测量一些文本的边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C# 编写一个要转储 SVG 文件的程序.我想知道是否有任何方法可以测量 C# 程序中一段文本的大小.我可以假设我知道字体和字体大小.但是字母的平均大小"*number_of_letters 非常不准确.

I am writing a program that is going to dump an SVG file, in C#. I was wondering if there is any way of measuring how big a piece of text is going to be from the C# program. I can assume that I know the font and fontsize. But the "average size of letter"*number_of_letters is very inaccurate.

我正在寻找这样的选项:1) 只需从字体大小和字体中找出文本有多大.2)我可以转储一次 SVG,然后从那里获取度量(通过以某种方式渲染它?然后从中读取该信息,以某种方式?)

I am looking for some option like this: 1) Just figure out, from font size and font, how big the text is. 2) I could dump the SVG once, and get the measure from there (by rendering it somehow? and then reading that information from it, somehow?)

谢谢!

推荐答案

想通了:

Font stringFont = new Font("Verdana", 8, GraphicsUnit.Pixel);
Image newImage = new Bitmap(10, 10);
Graphics g = Graphics.FromImage(newImage);
SizeF stringSize = new SizeF();
g.PageUnit = GraphicsUnit.Pixel;
stringSize = g.MeasureString("Hello, this is \n a string and stuff", stringFont);

这篇关于SVG:从 C# 测量一些文本的边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆