The Vb.Net application creates a bitmap from scratch and either converts to a tiff or se开发者_如何学Pythonnds it to a printer. In both cases, the quality of the image (in this case the font) is not good at all. The sample code listed below creates the graphics object that I use to write to the image.
Dim gr2 As Graphics = Graphics.FromImage(New Bitmap(800, 1000), Imaging.PixelFormat.Format32bppPArgb))
Along with what @durilai said you might want to kick up the resolution if you're going to be printing. .Net uses the system resolution which is normally 96 DPI but printers can work 300 DPI or greater files.
'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
I used these methods, play around with them they make a HUGE difference. These is C#, but you can see what is needed. Sorry.
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);
}
I used these methods for fonts:
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
精彩评论