简体   繁体   中英

System.Drawing.Graphics.DrawString() looks weird on Ubuntu

I'm trying to generate a picture for users when they join and leave a server on Discord. Everything went great, until what I was getting as picture on Windows, looked very different on Ubuntu (view examples down below). I tried different ways of TextRendering , like TextRenderingHint.SingleBitPerPixelGridFit , but none worked. The fonts I used both times are exactly the same, yet on Ubuntu it looks very jagged.

using (Graphics grD = Graphics.FromImage(img))
{
    grD.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
    grD.DrawString(message, WelcomeFont, drawBrush, x1, y1, drawFormat);
    grD.DrawString(name, UsernameFont, drawBrush, x2, y2, drawFormat);
    grD.DrawString(server, ServerFont, drawBrush, x3, y3, drawFormat);

    img = new Bitmap(img, new Size(400, 225));

    return img;
}

Could someone please tell me how I can fix this?

Images:

图片1图片2

Draw the image twice as wide and twice as high and see if the quality improves. It it is to be displayed in a web page or WPF application, the image can be scaled by the browser or WPF application's UI with better results.

.NET core image codecs are not the best.

There are some .net core API settings for text quality also when drawing a text string.

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