save an image as a bitmap without losing quality

后端 未结 1 882
野性不改
野性不改 2020-12-10 20:55

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 simila

相关标签:
1条回答
  • 2020-12-10 21:28

    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:

    0 讨论(0)
提交回复
热议问题