0

I know most people are always trying to get smooth settings but this time, since I am printing a barcode, I need to find out how to tell e.Graphics to print my image with the sharpest possible settings. Keep in mind that my current settings produce the best I was able to test so far but, once i print it to a file and zoom in 500%, you can still see a bit of smoothness.

Here's my code so far:

private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
{

    double pdf417_widthDPI = Math.Round(((double)picpdf417.Image.Width / (double)288) * 2, 2);
    double pdf417_heightDPI = Math.Round(((double)picpdf417.Image.Height / (double)288) * 2, 2);

    int newWidth = (int)Math.Round(pdf417_widthDPI * 96);
    int newHeight = (int)Math.Round(pdf417_heightDPI * 96);

    Rectangle pdf417_location_size = new Rectangle(0, 100, newWidth, newHeight);

    e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
    e.Graphics.SmoothingMode = SmoothingMode.None;
    e.Graphics.InterpolationMode = InterpolationMode.Low;
    e.Graphics.PixelOffsetMode = PixelOffsetMode.None;

    e.Graphics.DrawImage(picpdf417.Image, pdf417_location_size);
}
abatishchev
  • 98,240
  • 88
  • 296
  • 433
suchislife
  • 4,251
  • 10
  • 47
  • 78
  • 1
    Maybe you should try `InterpolationMode.NearestNeighbor`: http://stackoverflow.com/a/5606326/622391 – Simon MᶜKenzie Apr 04 '13 at 06:08
  • Close but... not 100% sharp. Any thoughts? – suchislife Apr 04 '13 at 06:14
  • 1
    I suspect that if you're not painting your image into an area whose height and width are integer multiples of the original, you're likely to get greyness. If you try this, do you see any improvement? – Simon MᶜKenzie Apr 04 '13 at 06:16
  • Let's see... the original is 290 x 78. The resize puts it at 193 x 52. – suchislife Apr 04 '13 at 06:19
  • As a test, just paint it at full size (even though it won't fit) - is it sharper? An alternative could be to paint into an intermediate buffer, then use [LockBits](http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx) and round each pixel off to either black or white. Note that there's a potential issue here where the bars will be moved slightly by this rounding - make sure you're within tolerance for the standard! Of course the best solution is to generate the original barcode at the exact final size you need... – Simon MᶜKenzie Apr 04 '13 at 06:25
  • Painted at full size still not 100% sharp. Interestingly enough, if I save the barcode to a file, this file can be zoomed in without losing its sharpness. – suchislife Apr 04 '13 at 06:33
  • If you're printing to a file, then zooming in 500%, it's likely that your file viewer is actually anti-aliasing the image. Do you see unsharpness when you print? – Simon MᶜKenzie Apr 09 '13 at 10:00

0 Answers0