c#绘制线条正在为某些尺寸的某些字体添加轮廓或掉落阴影
我正在使用C#牵引线在图像背景上绘制文本,该文本是输出的,作为打印的TIFF。
对于某些尺寸的字体,绘图方法是在文本周围添加边框。这两个示例都是使用相同的代码绘制的,仅具有不同的字体尺寸。第一个是10pt,第二点是12pt。
在其他字体上,此更改发生在较大尺寸。就像我使用新罗马时代的时代一样,轮廓才发生到18pt,然后消失。
这就是我创建背景映像的方式(我知道我应该使用“使用”,只是还没有这样做):
protected Image CreateCTextBackground() {
// TODO Get DPI from template
Bitmap background = new Bitmap(TEXT_RECT_WIDTH, TEXT_RECT_WIDTH);
background.SetResolution(360f, 360f);
Graphics graphics = Graphics.FromImage(background);
graphics.Clear(Color.Transparent);
graphics.Save();
return background;
}
创建一个字体:
protected Font CreateFont(TextFeature textFeature) {
FontFamily fontFamily = new FontFamily(textFeature.FontFamily);
Font font = new Font(
fontFamily,
textFeature.FontSize,
GraphicsUnit.Point);
return font;
}
然后我在借鉴:
Image textBackground = CreateCTextBackground();
Graphics textGfx = Graphics.FromImage(textBackground);
Brush textBrush = new SolidBrush(fontColor);
log.Debug($"xPos={xPos},yPos={yPos}");
textGfx.TranslateTransform(xPos, yPos);
textGfx.RotateTransform(270);
textGfx.DrawString(textFeature.Text, font, textBrush, textGfx.VisibleClipBounds, stringFormat);
我不确定我在做什么错误的。任何建议将不胜感激。
I'm using C# DrawString to draw text on an image background which is output as a TIFF for printing.
For some fonts at some sizes, the DrawString method is adding a border around the text. Both of these examples are drawn using the same code, just with different font sizes. The first is 10pt and the second is 12pt.
On other fonts, this change happens at larger sizes. Like if I use Times New Roman, the outline occurs up until 18pt and then it goes away.
This is how I'm creating the background image (I know I should use "using", just not doing so yet):
protected Image CreateCTextBackground() {
// TODO Get DPI from template
Bitmap background = new Bitmap(TEXT_RECT_WIDTH, TEXT_RECT_WIDTH);
background.SetResolution(360f, 360f);
Graphics graphics = Graphics.FromImage(background);
graphics.Clear(Color.Transparent);
graphics.Save();
return background;
}
Creating a font:
protected Font CreateFont(TextFeature textFeature) {
FontFamily fontFamily = new FontFamily(textFeature.FontFamily);
Font font = new Font(
fontFamily,
textFeature.FontSize,
GraphicsUnit.Point);
return font;
}
And then I'm drawing on it:
Image textBackground = CreateCTextBackground();
Graphics textGfx = Graphics.FromImage(textBackground);
Brush textBrush = new SolidBrush(fontColor);
log.Debug(quot;xPos={xPos},yPos={yPos}");
textGfx.TranslateTransform(xPos, yPos);
textGfx.RotateTransform(270);
textGfx.DrawString(textFeature.Text, font, textBrush, textGfx.VisibleClipBounds, stringFormat);
I'm not sure what I'm doing wrong. Any advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论