PNG文件的质量很差

时间:2016-01-17 19:57:22

标签: c# graphics png system.drawing

处理需要我创建运输标签并将其存储为PNG的项目。我设置了布局,当我查看PNG文件时,一切看起来都不错,但是当我在热/喷墨/激光打印机上打印时,质量非常糟糕。

我已经搜遍了所有但我找不到任何似乎可以解决我的问题。我不是一个图形人,但我想知道我是否需要以更高的分辨率构建文件,但最终结果需要是一个4乘6的运输标签。提高图像质量的最佳方法是什么?

以下是用于生成PNG文件的代码:

                Bitmap bitMapImage = new System.Drawing.Bitmap("blanklabel.png");
                Graphics graphicImage = Graphics.FromImage(bitMapImage);
                graphicImage.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                string dttime = DateTime.Now.ToString("HHmmss");

                // Create pen.
                Pen blackPen0 = new Pen(Color.Gray, 1);
                Pen blackPen1 = new Pen(Color.Black, 1);
                Pen blackPen2 = new Pen(Color.Black, 2);
                Pen blackPen3 = new Pen(Color.Black, 3);

                //Top Rectangle - Draw Box
                Rectangle topRect = new Rectangle(5, 5, 367, 338);
                graphicImage.DrawRectangle(blackPen1, topRect);
                //Top Rectangle - Horizontial Lines
                graphicImage.DrawLine(blackPen1, 5, 41, 372, 41);
                graphicImage.DrawLine(blackPen1, 5, 77, 372, 77);
                graphicImage.DrawLine(blackPen2, 5, 129, 372, 129);
                graphicImage.DrawLine(blackPen2, 5, 210, 372, 210);
                graphicImage.DrawLine(blackPen0, 5, 225, 372, 225);  //Draw row1 in middle
                graphicImage.DrawLine(blackPen0, 5, 240, 372, 240);  //Draw row2 in middle
                graphicImage.DrawLine(blackPen0, 5, 255, 372, 255);  //Draw row3 in middle
                graphicImage.DrawLine(blackPen1, 5, 271, 372, 271);
                graphicImage.DrawLine(blackPen1, 5, 322, 372, 322);
                //Top Rectangle - Vertical Lines
                graphicImage.DrawLine(blackPen1, 258, 41, 258, 322);
                graphicImage.DrawLine(blackPen1, 103, 210, 103, 271);
                graphicImage.DrawLine(blackPen1, 172, 210, 172, 271);
                //graphicImage.DrawLine(blackPen1, 257, 210, 257, 271);                    
                graphicImage.DrawLine(blackPen1, 304, 210, 304, 271);

                //Top Rectangle - Label Text
                graphicImage.DrawString("Shipper's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 43));
                graphicImage.DrawString("Receiver's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 79));
                graphicImage.DrawString("Origin", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 43));
                graphicImage.DrawString("Destination", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 79));
                graphicImage.DrawString("Time-definite type", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 131));
                graphicImage.DrawString("Total packages", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 213));
                graphicImage.DrawString("Total Actual weight", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 228));
                graphicImage.DrawString("Total Chargeable weight", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 243));
                graphicImage.DrawString("Freight Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(10, 258));
                graphicImage.DrawString("Additional Service", new Font("Arial", 6), SystemBrushes.WindowText, new Point(180, 213));
                graphicImage.DrawString("Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(264, 213));
                graphicImage.DrawString("Total Charges", new Font("Arial", 6), SystemBrushes.WindowText, new Point(310, 213));
                graphicImage.DrawString("Payment Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 275));
                graphicImage.DrawString("Credit Account No.:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 290));
                graphicImage.DrawString("3rd Party District code:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 305));
                graphicImage.DrawString("Receiver's Signature:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 275));
                graphicImage.DrawString("Delivery Date:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(263, 305));
                graphicImage.DrawString("Remarks:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 327));

                //Bottom Rectangle - Draw Box
                Rectangle bottomRect = new Rectangle(5, 349, 367, 211);
                graphicImage.DrawRectangle(blackPen1, bottomRect);
                //Bottom Rectangle - Horizontial Lines
                graphicImage.DrawLine(blackPen1, 258, 377, 372, 377);
                graphicImage.DrawLine(blackPen1, 5, 401, 258, 401);
                graphicImage.DrawLine(blackPen1, 5, 468, 372, 468);
                graphicImage.DrawLine(blackPen1, 5, 528, 372, 528);
                //Bottom Rectangle - Vertical Lines
                graphicImage.DrawLine(blackPen1, 258, 349, 258, 560);
                //Bottom Rectangle - Label Text
                graphicImage.DrawString("Shipment Type:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 352));
                graphicImage.DrawString("Description of Contents:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 380));
                graphicImage.DrawString("Declared value for Customs:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 420));
                graphicImage.DrawString("Country of Origin:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 450));
                graphicImage.DrawString("Shipper's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 404));
                graphicImage.DrawString("Receivers's Information:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 471));
                graphicImage.DrawString("Total Charges:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 471));
                graphicImage.DrawString("Payment Information:", new Font("Arial", 6), SystemBrushes.WindowText, new Point(261, 495));
                graphicImage.DrawString("Customer remarks:", new Font("Arial", 7, FontStyle.Bold), SystemBrushes.WindowText, new Point(10, 538));
                //Bottom Rectangle - Self Drop Selection Box
                Rectangle bottomselectRect1 = new Rectangle(261, 538, 12, 12);
                graphicImage.DrawRectangle(blackPen1, bottomselectRect1);
                //Bottom Rectangle - Self Pickup Selection Box
                Rectangle bottomselectRect2 = new Rectangle(313, 538, 12, 12);
                graphicImage.DrawRectangle(blackPen1, bottomselectRect2);
                graphicImage.DrawString("Self-drop:", new Font("Arial", 5), SystemBrushes.WindowText, new Point(276, 541));
                graphicImage.DrawString("Self-pickup:", new Font("Arial", 5), SystemBrushes.WindowText, new Point(328, 541));

                HttpContext.Current.Response.ContentType = "image/png";

                bitMapImage.Save("test_label_" + dttime + ".png", ImageFormat.Png);
                blackPen0.Dispose();
                blackPen1.Dispose();
                blackPen2.Dispose();
                blackPen3.Dispose();
                graphicImage.Dispose();
                bitMapImage.Dispose();

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

这只是部分答案,但可能有所帮助。这是你的形象: Image Dinensions:377 x 566像素 10.19 x 15.30厘米 每厘米像素数:37 它可能有助于了解您的输出设备使用的是什么,但我使用的大多数喷墨打印机都满意每英寸300像素(或300 dpi的倍数)。其他决议必须按比例缩放,这对于如此精细的细节可能是灾难性的。 您是否有可用于修改PNG分辨率和缩放比例的图形程序,以便您可以在不必更改程序的情况下进行实验? (我使用的是古老版本的不再可用的Paint Shop Pro,但我也有Corel Photo Paint也能完成这项工作。)如果你没有任何东西,你可以试试gimp (免费的位图软件)。