Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:27:02+00:00 2026-05-28T15:27:02+00:00

Since I’ve tried to draw string with every combination of smoothing and rendering with

  • 0

Since I’ve tried to draw string with every combination of smoothing and rendering with Graphics.DrawString() I was thinking that text renderer would do a better job drawing my strings but I think was wrong.

This is how it is supposed to look like:

enter image description here

And this is how it looks like:

enter image description here

Here is my code:

Graphics objGraphics2 = Graphics.FromImage(objBitmap);

objGraphics2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
objGraphics2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
objGraphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
objGraphics2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

Font textFont = new Font(textFontFamily, PxtoEm(textSize));

SolidBrush b = new SolidBrush(textColor);

TextRenderer.DrawText(objGraphics2, textValue, textFont, new Rectangle(0, 0, Width, Height), textColor);

Is my PxtoEm method wrong?

public float PxtoEm(int px)
{
      float em = (float)(Convert.ToDouble(Convert.ToDouble(px) * Convert.ToDouble(72) / Convert.ToDouble(objBitmap.HorizontalResolution)));
      return em;
}

I need some suggestions because this is really awful, it gets worse with larger fonts and images aren’t shrunk.

UPDATE: Got it working with bigger fonts(ie. 20px) but with smaller fonts it gets kind of erased on some letters:

This is how it’s suposed to be with font Arial 10px:

enter image description here

This is result with Graphics.DrawString()

enter image description here

As you can see it really isn’t very good but closest I got. I made some changes to code and got better results with larger font:

This is how it’s suposed to be with font Arial 20px:

enter image description here

This is drawing result:

enter image description here

And here is the changed code(I droped em method and used pixels directly, switched to Graphics.DrawString() instead of TextRenderer.DrawText()

  Graphics objGraphics = Graphics.FromImage(objBitmap);
  objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
  objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  objGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
  Font textFont = new Font(textFontFamily, textSize,GraphicsUnit.Pixel);
  SolidBrush b = new SolidBrush(textColor);
  PointF origin = new PointF((float)TextLeft,(float)TextTop);
  StringFormat format = StringFormat.GenericTypographic;

  objGraphics.DrawString(textValue, textFont, b , origin, format);

If someone has some suggestion to maybe write different method for smaller text sizes and use above code for larger as it works nicely, post it and I’ll try it!

UPDATE 3: Finally found solution for everything, and solution was rather simple:
DON’T USE TRANSPARENT BACKGROUND!

And settings are:

 objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // <-- important!
 objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
 objGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
          objGraphics.TextContrast = 0;

Here is final image with these settings on white background:

enter image description here

Exactly the same, thanks for suggestions and replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:27:03+00:00Added an answer on May 28, 2026 at 3:27 pm

    I built something to generate image buttons using similar functionality and I had issues with kerneling and the font not stretching to the desired with. The following settings got me really close to what I wanted but still not 100%.

    objGraphics2.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
    objGraphics2.TextRenderingHint = System.Drawing.Drawing2D.TextRenderingHint.AntiAliasGridFit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since performance of string concatenation is quite weak in VB6 I'm testing several StringBuilder
since they have same rendering engine, this problem shows in both. it works great
Since recent runtimes in iOS, we are able to define properties that will generate
Since Qt doesnt allow templates in their slots, I tried to do the following
Since I'm using Java 1.4.2, this means that I cannot use Java's implementation of
Since Java 5, we've had boxing/unboxing of primitive types so that int is wrapped
since undefined equates to false, i am wondering if there are any draw backs
Since every class in java is a subclass of the Object, and variables in
Since it's impossible to capture text from a java canvas by using standard Windows
Since I'm new to cake, I understand there is a log of magic that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.