3

I had a problem of printing quality and I described it in this link : enter link description here

I tried many different solutions that helped other guys with similar prob but they don't work for me because I have a new prob of saving image as bitmap(with low quality)

finally I decided to ask my current question , because as u see in above link , my prob starts after saving the image in system(96dpi) and restoring it . but I have no way so I'm looking for a way that make it possible to save an image (that has pixels drawn from a graphic) without losing quality.

thanx in advance

Community
  • 1
  • 1
Shima.Y
  • 373
  • 4
  • 9
  • 18
  • Don't fully understand your question, but I see two things that don't fit well togetter, and thats "96dpi" and "printing". You need at least 300dpi to get a decent printing result. Therefore I think the answer is that you just need a higher resolution bitmap. – huysentruitw Jul 28 '12 at 08:14

1 Answers1

7

While 96 dpi is fine for screen display, it is not for printing. For printing you need at least 300 dpi to make it look sharp.

Out of curiosity I created a C# console application that prints a text on a 600 dpi bitmap. I came up with this:

class Program
{
    public static void Main(string[] args)
    {
        const int dotsPerInch = 600;    // define the quality in DPI
        const double widthInInch = 6;   // width of the bitmap in INCH
        const double heightInInch = 1;  // height of the bitmap in INCH

        using (Bitmap bitmap = new Bitmap((int)(widthInInch * dotsPerInch), (int)(heightInInch * dotsPerInch)))
        {
            bitmap.SetResolution(dotsPerInch, dotsPerInch);

            using (Font font = new Font(FontFamily.GenericSansSerif, 0.8f, FontStyle.Bold, GraphicsUnit.Inch))
            using (Brush brush = Brushes.Black)
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.Clear(Color.White);
                graphics.DrawString("Wow, I can C#", font, brush, 2, 2);
            }
            // Save the bitmap
            bitmap.Save("n:\\test.bmp");
            // Print the bitmap
            using (PrintDocument printDocument = new PrintDocument())
            {
                printDocument.PrintPage += (object sender, PrintPageEventArgs e) =>
                {
                    e.Graphics.DrawImage(bitmap, 0, 0);
                };
                printDocument.Print();
            }
        }
    }
}

This is the printed result

This is the printed result:

huysentruitw
  • 27,376
  • 9
  • 90
  • 133
  • 2
    Also note that you should never antialias text and lines when printing. Otherwise the gray edges become fuzzy edges on paper. – Joey Jul 28 '12 at 08:55
  • @WoutwrH:my project's process is exactly the same as your example . I just added SetResolution and it improved my text quality but magnified my text ! how can I solve it ? – Shima.Y Jul 28 '12 at 13:04
  • @Joey : aha , thanx for Ur guidance :) – Shima.Y Jul 28 '12 at 13:04
  • @Shima, this is hard to tell without seeing any line of code. You can modify your question and add some code. Also note in my example that a bitmap of 3600 pixels by 600 pixels is created, so if you open the bitmap at full resolution, the text will indeed be very large. But that is normal, since we have a 600dpi resolution that you open on a 96dpi screen. – huysentruitw Jul 28 '12 at 13:18
  • Also don't mix up units like inch, pixels, points... Work everything out in one unit and perform calculations where needed (like I did with `new Bitmap((int)(widthInInch * dotsPerInch), ...`). Also set the size of the font with a value in the same unit: f.e. `Font(FontFamily.GenericSansSerif, 0.8f, FontStyle.Bold, GraphicsUnit.Inch)` sets the size to 0.8inch. – huysentruitw Jul 28 '12 at 13:20
  • @WouterH: well it's hard to add some codes , there are a lot of methods that calls each other and all the process divided between these methods , but let me say that the last result that I has gotten after making some changes in resolution is that my image transfered to the top left corner of my bitmap and my bitmap got larger ! – Shima.Y Jul 29 '12 at 08:06
  • @WouterH : I could do it but it really slow down my run time ! – Shima.Y Jul 30 '12 at 06:42