在VB.Net中从头开始创建位图图像时,质量很糟糕吗?

时间:2010-03-19 15:30:04

标签: vb.net image bitmap tiff

Vb.Net应用程序从头开始创建位图,并转换为tiff或将其发送到打印机。在这两种情况下,图像的质量(在这种情况下是字体)都不是很好。下面列出的示例代码创建了我用来写入图像的图形对象。

Dim gr2 As Graphics = Graphics.FromImage(New Bitmap(800, 1000), Imaging.PixelFormat.Format32bppPArgb))

2 个答案:

答案 0 :(得分:11)

除了@durilai所说的,如果你要打印,你可能想要提出决议。 .Net使用的系统分辨率通常为96 DPI,但打印机可以使用300 DPI或更高的文件。

    '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

答案 1 :(得分:0)

我使用这些方法,与它们一起玩,它们会产生巨大的差异。这些是C#,但你可以看到需要什么。遗憾。

  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;