简体   繁体   中英

graphics.DrawString() not properly rendering

I'm trying to render some text onscreen in Monogame by drawing a string to a Texture2D

This is the output I currently have

错误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

在此处输入图像描述

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

在此处输入图像描述

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