c# - 将图像保存为位图而不会降低质量

标签 c# bitmap graphic

我遇到了打印质量问题,我在这个链接中描述了它: enter link description here

我尝试了许多不同的解决方案,这些解决方案帮助了其他有类似问题的人,但它们对我不起作用,因为我有一个将图像保存为位图(低质量)的新问题

最后我决定问我当前的问题,因为正如您在上面的链接中看到的,我的概率在将图像保存到系统 (96dpi) 并恢复它之后开始。但我没有办法,所以我正在寻找一种方法,可以在不降低质量的情况下保存图像(具有从图形中绘制的像素)。

提前致谢

最佳答案

虽然 96 dpi 适合屏幕显示,但不适用于打印。对于打印,您至少需要 300 dpi 才能使其看起来清晰。

出于好奇,我创建了一个 C# 控制台应用程序,用于在 600 dpi 位图上打印文本。 我想到了这个:

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:

关于c# - 将图像保存为位图而不会降低质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11699219/

相关文章:

pdf - 导入 *.pdf_tex 文件错误

c# - Excel-C# : How to read the formulas from a cell?

c# - 将驻留字符串转换为对象后为假

python - wxPython框架上的背景图像

C#加载JPG文件,提取BitmapImage

Java图形(颜色和字体)

c# - Lucene 支持 Unicode 吗?

c# - WPF中使用INotifyPropertyChanged绑定(bind)系统相关信息

bitmap - Notepad++ 的图标使用什么位图格式(这样我就可以更改它们)?

Java Graphics 2D UI 箭头方向