When creating a bitmap from scratch in VB.Net, does the quality stink?

The Vb.Net application creates a bitmap from scratch and either converts to tiff or sends it to the printer. In both cases, the image quality (in this case, the font) is not very good. The sample code below creates a graphic object that I use to write to an image.

Dim gr2 As Graphics = Graphics.FromImage(New Bitmap(800, 1000), Imaging.PixelFormat.Format32bppPArgb))
+5
source share
2 answers

Along with what @durilai said you would like to raise the resolution if you are going to print..Net uses a system resolution that is usually 96 DPI, but printers can work with files of 300 DPI or more.

    'Create a new bitmap
    Using Bmp As New Bitmap(800, 1000, Imaging.PixelFormat.Format32bppPArgb)
        'Set the resolution to 300 DPI
        Bmp.SetResolution(300, 300)
        'Create a graphics object from the bitmap
        Using G = Graphics.FromImage(Bmp)
            'Paint the canvas white
            G.Clear(Color.White)
            'Set various modes to higher quality
            G.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
            G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

            'Create a font
            Using F As New Font("Arial", 12)
                'Create a brush
                Using B As New SolidBrush(Color.Black)
                    'Draw some text
                    G.DrawString("Hello world", F, B, 20, 20)
                End Using
            End Using
        End Using

        'Save the file as a TIFF
        Bmp.Save("c:\test.tiff", Imaging.ImageFormat.Tiff)
    End Using
+10
source

, , . #, , . .

  Bitmap bm = new Bitmap(iWidth, iHeight);
  using (Graphics graphics = Graphics.FromImage(bm))
  {
    graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    graphics.DrawImage(bmOriginal, 0, 0, iWidth, iHeight);
  }

:

  graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
  graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
0

All Articles