title: C# DrawString() resolution
body: <p>I am drawing a string on a PictureBox using <code>DrawString()</code> inside <code>OnPaint()</code>. It looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/HgHUp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HgHUp.png" alt="enter image description here"></a></p>
  
  <p>Now when I draw the exact same string on a <code>Graphics</code> object obtained from <code>Graphics.FromImage()</code> the string is much smaller and unreadable. The image I draw on is <code>5184 x 3456</code> and the font is declared as follows:</p>
  
  <p><code>new Font("Arial", 16.0f, FontStyle.Regular, GraphicsUnit.World);</code></p>
  
  <p>I tried all <code>GraphicsUnit</code>s, but it makes absolutely no difference. How do I draw the font independent from image resolution? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I fail to see how the "draw code" is relevant in this case, but here you go:</p>
  
  <pre><code>void DrawOverlay(Graphics g, Font fnt, int containerWidth, int containerHeight)
          {
              if (!OverlayCheck.Checked)
                  return;
  
              float padding = 5.0f;
              float offset = 5.0f;
  
              StringBuilder sb = new StringBuilder();
              sb.AppendFormat("{0}\n", ISOComboBox.Text);
              sb.AppendFormat("Exp. Time: {0}\n", TVComboBox.Text);
              sb.AppendFormat("Aperture: {0}\n", AVComboBox.Text);
  
              using (var tb = new SolidBrush(Color.FromArgb(150, 0,0,0)))
              {
                  string infoStr = sb.ToString();
                  SizeF infoStrSize = g.MeasureString(infoStr, fnt);
                  var infoStrDim = new SizeF(infoStrSize.Width + padding * 2, infoStrSize.Height + padding * 2);
  
                  g.FillRectangle(tb, offset, containerHeight - offset - infoStrDim.Height, infoStrDim.Width, infoStrDim.Height);
                  g.DrawString(infoStr, fnt, Brushes.White, offset + padding, containerHeight - infoStrDim.Height);
  
                  if (TitleTextBox.Text.Length &gt; 0)
                  {
                      var titleStr = SpliceText(TitleTextBox.Text, 15);
                      SizeF titleStrSize = g.MeasureString(titleStr, fnt);
                      var titleStrDim = new SizeF(titleStrSize.Width + padding * 2, titleStrSize.Height + padding * 2);
  
                      g.FillRectangle(tb, offset, offset, titleStrDim.Width, titleStrDim.Height);
                      g.DrawString(titleStr, fnt, Brushes.White, offset + padding, offset + padding);
                  }
              }
          }
  </code></pre>
  
  <p>Some background: The image drawn on the PictureBox is a low-res, live stream from a camera. <code>DrawOverlay()</code> is called inside OnPaint() to render the text overlay.</p>
  
  <p>When the camera captures a picture it has has higher resolution (5184 x 3456). I create a graphics context from that image (<code>Graphics.FromImage()</code>) and 
  <code>DrawOverlay()</code> again. This time the text is way smaller, which makes sense due to higher resolution. I want the text to have equal size in both images.</p>
  
  <p>The live view has 96/96 dpi (DpiX, DpiY), while the high-res image has 72/72. So I need to scale the font relative to dpi.</p>