[英]Setting Font in CGBitmapContext.SelectFont using variable
I'm trying to write a general purpose routine that will set the font using a variable instead of the literal font name. 我正在尝试编写一个通用例程,该例程将使用变量而不是文字字体名称来设置字体。
CGBitmapContext.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
instead of: 代替:
CGBitmapContext.SelectFont("Arial", fontSize, CGTextEncoding.MacRoman);
But it seems not to work. 但这似乎行不通。 Any suggestions would be much appreciated.
任何建议将不胜感激。
Thanks, Rick 谢谢,瑞克
Please post a more complete sample, the following code works for me: 请发布更完整的示例,以下代码对我有用:
context.SetFillColor (0.0f, 1.0f);
context.SelectFont ("Arial", 28, CGTextEncoding.MacRoman);
context.ShowTextAtPoint (pageRect.GetMidX (), pageRect.GetMidY (), "Hello Select Font (string)");
string font = "Arial";
context.SelectFont (font, 28, CGTextEncoding.MacRoman);
context.ShowTextAtPoint (pageRect.GetMidX (), pageRect.GetMidY () + 40, "Hello Select Font (var)");
Both lines uses Arial and it still works if I switch them (using the var first). 这两行都使用Arial,并且如果我切换它们(仍然先使用var)仍然可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.