简体   繁体   English

graphics.DrawString() 未正确渲染

[英]graphics.DrawString() not properly rendering

I'm trying to render some text onscreen in Monogame by drawing a string to a Texture2D我正在尝试通过将字符串绘制到 Texture2D 在 Monogame 屏幕上呈现一些文本

This is the output I currently have这是我目前拥有的 output

错误1

this is what i want it to look like这就是我想要的样子

正确的

and here is a snippet of the code这是代码片段

Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);

g.Clear(System.Drawing.Color.Transparent);

//Quality settings
g.SmoothingMode      = SmoothingMode.HighQuality;
g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

Brush brush = new SolidBrush(Color.White);

g.DrawString(text, f, brush, 0, 0);

After reading some of the other posts about the same issue I tried clearing with the colour white, didn't change anything, then I tried adding a bunch of graphics settings like this post said to and that only gave me在阅读了有关同一问题的其他一些帖子后,我尝试用白色清除,没有改变任何东西,然后我尝试像这篇帖子所说的那样添加一堆图形设置,这只给了我

错误2

Which has a bunch of unwanted black dots around it, which is arguably better then the first result but still not the crisp text I need, and clearing it with a single colour wont work because this text could potentially be on an image or something that moves它周围有一堆不需要的黑点,可以说比第一个结果更好,但仍然不是我需要的清晰文本,并且用单一颜色清除它是行不通的,因为该文本可能位于图像或移动的东西上

EDIT: i was able to get it slightly better with TextRenderingHint.SingleBitPerPixelGridFit编辑:我能够使用TextRenderingHint.SingleBitPerPixelGridFit稍微好一点

在此处输入图像描述

Still isnt what i want but at least closer仍然不是我想要的,但至少更接近

I was finally able to fix it with the help of some people in the monogame discord by settings BlendState to Nonpremultiplied in the sprite batch where the text is drawn to我终于能够在monogame Nonpremultiplied中的一些人的帮助下修复它

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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