3

I'm trying to print my photo through c#. My printer is EPSON L351. When printing through Windows picture viewer, the photo quality is quite high. But when I print the photo through c#, it just keep blurry. The photo has the size of 1286.76*1930.4. Click here to get the picture.

Here's my code. I don't know what wrong with it. Am I missing something to set up the printer?

    private void button1_Click(object sender, EventArgs e)
    {
        this.printDocument1.PrinterSettings.PrinterName = "EPSON L350 Series";

        PaperSize ps = new PaperSize("Custom Size 1", 400, 600);
        this.printDocument1.DefaultPageSettings.PaperSize = ps;
        this.printDocument1.DefaultPageSettings.PrinterResolution = this.printDocument1.PrinterSettings.PrinterResolutions[0];           
        this.printDocument1.DefaultPageSettings.Landscape = false;
        this.printDocument1.DefaultPageSettings.Margins.Left = 0;
        this.printDocument1.DefaultPageSettings.Margins.Top = 0;
        this.printDocument1.DefaultPageSettings.Margins.Right = 0;
        this.printDocument1.DefaultPageSettings.Margins.Bottom = 0;
        this.printDocument1.Print();
    }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        try
        {
            printDocument1.DocumentName = "Bonnie";

            Image newImage = Image.FromFile(@"C:\W (22).jpg");

            e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.DrawImage(newImage, 0, 0, 400, 600);

            printDocument1.Dispose();
            newImage.Dispose();
        }
        catch (Exception ex)
        {
        }
    }

Hoping help from you!!!!

  • I've never had occasion to print an image from C# but I'm very leery of the 400, 600 dimension I see. It feels like you're cutting your resolution to those numbers which would cause your blurriness. – Loren Pechtel Sep 26 '15 at 02:03
  • @LorenPechtel Thank you for your answer! The numbers 400 and 600 are used to match the size of paper(4inch * 6inch). If I use `e.Graphics.DrawImage(newImage, 0, 0);`, it will only print part of the photo. – bonnie_love Sep 26 '15 at 02:12
  • In other words, you're printing at 100dpi. Of course it's blurry! – Loren Pechtel Sep 26 '15 at 02:17
  • @LorenPechtel So how can I set the dpi to 300? My printer seems has dpi of 300. – bonnie_love Sep 26 '15 at 02:27
  • As I said, I haven't actually tried to print images before. I would be inclined to try 1200x1800. – Loren Pechtel Sep 26 '15 at 02:30
  • @LorenPechtel I've tried 1200*1800. It printed only a part of the photo. Thank you anyway! – bonnie_love Sep 26 '15 at 02:48
  • I just realized something--those dimensions are width, height. Is that really how your image is, or should you flip the dimensions? – Loren Pechtel Sep 26 '15 at 02:50
  • _The photo has the size of 1286.76*1930.4_ __No__, the image has a size of __427x641__ pixels. It looks good on screen with, say, __96dpi__ but when you print it at __600dpi__ or so it will be very small or rather blurry. Your choice but __no way__ to make it crips __and__ large. – TaW Sep 26 '15 at 08:06

0 Answers0