views:

528

answers:

2

The Vb.Net application creates a bitmap from scratch and either converts to a tiff or sends 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))
A: 

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;
Dustin Laine
It's slightly better, but the curved fonts still look really bad.
ajl
Check my addition, I did not see you were doing fonts.
Dustin Laine
Same comment as above - So it looks to be getting better, but it's still not the best. For example, when I line up 2 printed doc - one bitmap and one word doc - the bitmap looks like it printed from an old dot matrix printer - each character is made up of little dots. Any other suggestions?
ajl
+3  A: 

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
Chris Haas
+1 Good point, will impact file size significantly.
Dustin Laine
So it looks to be getting better, but it's still not the best. For example, when I line up 2 printed doc - one bitmap and one word doc - the bitmap looks like it printed from an old dot matrix printer - each character is made up of little dots. Any other suggestions?
ajl
How are you printing it?
Chris Haas
When printing out of a standard tiff viewer it's OK quality. When looking at the image and zooming in, you can see the fonts look poor. I'm really trying to get word document quality text.
ajl
Okay, I just want to make sure we're on the same page here. Are you talking about how in Word you can increase the zoom level as much as you want and always end up with clean looking fonts? But then if you make an image in .Net and zoom it it looks pixelated? If so this is because you're starting with a Bitmap object which is by definition pixel-based. When you draw text .Net has to "rasterize" the font as pixels. TIFFs, JPGs and most image formats are raster-only, you need to look at something vector-based. You might want to explore WPF or writing PDFs with something like iTextSharp.
Chris Haas
I've experimented with printing from word to the blackice tiff driver. I guess this would be more a function of the driver instead of word, but the quality is better than anything I can get from creating .Net bitmaps and converting to tiff. I can't use the driver because the print process is too slow, but I can't match their quality. The suggestions on this thread have helped quality enormously, but still not there.
ajl
I just did a test and used the highest setting for Black Ice (TIFF Uncompressed, 24 bits, High Resolution 600x600, 8 1/2x11) and then updated the code above by changing the bitmap size to 5100x6000 and resolution to 600x600 (which is the same as Black Ice produces) and they look almost identical. I can see that Word to TIFF does include some LCD ClearType pixels (shades of orange) that actually are meant for screen, not print, but otherwise they look pretty much the same too me, especially when printed. Here's a screenshot of each zoomed into 700%: http://chris.vendiadvertising.com/Tiff.png
Chris Haas