title: C#/VB.NET: Howto improve anti-alias quality
body: <p>Question: <br />
  In Reporting Service, I need to have a vertical, starting at bottom, bottom-to-top, horizontally middle aligned text.</p>
  
  <p>The only way to do this is to create an image in code, and set this image into the title column.</p>
  
  <p>See the code below.<br />
  <br />
  Basically, it works fine, just that the anti-alias quality is pretty crappy.<br />
  Is there anything I can do to improve it ?<br />
  See below screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/8mdha.png" alt="SSRS Problem"></p>
  
  <p>The vertical text is somehow pale, and not full black, <br />
  and also there is smearing all around the text, in the background color.
  As well as it appears bolder than the text on the left, but both have format arial, size 8, bold
  <br /><br />
  I've tried all other values of <br />
  System.Drawing.Text.TextRenderingHint.*
  , as well as no anti-alias at all</p>
  
  <p>but the current one seems to be the least crappy.
  I've also tried to change the image format, to no avail:</p>
  
  <pre><code>Function LoadImage2(ByVal sImageText As String, ByVal sImageTextMax As String) As System.Drawing.Image
      sImageTextMax = sImageTextMax.PadRight(15)
      Dim iFontSize As Integer = 8 '//Change this as needed
      Dim bmpImage As New System.Drawing.Bitmap(1, 1)
      Dim iWidth As Integer = 0
      Dim iHeight As Integer = 0
      Dim bgColor As System.Drawing.Color = System.Drawing.Color.LemonChiffon ' LightGray
      Dim TextColor As System.Drawing.Color = System.Drawing.Color.Black
  
      Dim fsFontStyle As System.Drawing.FontStyle = System.Drawing.FontStyle.Bold
  
      '// Create the Font object for the image text drawing.
      Dim MyFont As New System.Drawing.Font("Arial", iFontSize, fsFontStyle, System.Drawing.GraphicsUnit.Point)
      '// Create a graphics object to measure the text's width and height.
      'Graphics(MyGraphics = Graphics.FromImage(bmpImage))
      Dim MyGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmpImage)
      '// This is where the bitmap size is determined.
      iWidth = MyGraphics.MeasureString(sImageTextMax, MyFont).Width
      iHeight = MyGraphics.MeasureString(sImageTextMax, MyFont).Height
      '// Create the bmpImage again with the correct size for the text and font.
      'bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iWidth, iHeight))
  
      'inches = pixels / dpi
      'pixel = inches * dpi
      '1 centimeter = 0.393700787 inch
      'pixel = cm * 0.393700787  * dpi
  
  
      ' vice-versa, because 270° turn
      iHeight = 1 * 0.393700787 * bmpImage.HorizontalResolution 'x DPI
      iWidth = 2.25 * 0.393700787 * bmpImage.VerticalResolution 'y DPI
  
  
      bmpImage = New System.Drawing.Bitmap(bmpImage, New System.Drawing.Size(iHeight, iWidth))
  
      '// Add the colors to the new bitmap.
      MyGraphics = System.Drawing.Graphics.FromImage(bmpImage)
      MyGraphics.Clear(bgColor)
      MyGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
  
      MyGraphics.TranslateTransform(0, iWidth)
      MyGraphics.RotateTransform(270)
  
      Dim iTextStartX As Single = 2
      Dim iTextStartY As Single = CSng(iHeight) / CSng(2.0) - CSng(iFontSize) / CSng(2.0)
      iTextStartY -= 2
  
      MyGraphics.DrawString(sImageText, MyFont, New System.Drawing.SolidBrush(TextColor), iTextStartX, iTextStartY)
      MyGraphics.Flush()
      Return bmpImage
  End Function
  
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Me.PictureBox1.Image = LoadImage2("test", "")
  End Sub
  
  
  
  ' This piece is only needed in reporting service itselfs
  Function LoadImage(ByVal strText As String) As Byte()
      Dim ThisImageFormat As System.Drawing.Imaging.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
  
  
      Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
      Dim bitmapBytes As Byte()
      Dim bmpImage As System.Drawing.Image = LoadImage2(strText, "")
  
  
      bmpImage.Save(stream, ThisImageFormat)
      bitmapBytes = stream.ToArray
      stream.Close()
      bmpImage.Dispose()
      Return bitmapBytes
  End Function
  </code></pre>