【问题标题】:Transform pixel height of image to printing size used by graphics object将图像的像素高度转换为图形对象使用的打印尺寸
【发布时间】:2009-04-28 09:26:27
【问题描述】:

作为我的应用程序打印过程的一部分,我正在尝试打印缩小到指定宽度并将一个放在另一个下方的图像列表。问题是我无法弄清楚如何将图像的像素高度转换为打印期间图形对象使用的单位高度。如何正确计算 imageHeightPrint 变量?

这段代码 sn-p 是图像打印循环的一部分,它按比例缩小图像并计算它的高度和下一张图像的位置。

Image image = Image.FromStream(imageStream);

// Get proportional correct height
int imageHeight = image.Height * imageWidth / image.Width;

Image imageToPrint = image.GetThumbnailImage(imageWidth, imageHeight, null, IntPtr.Zero);

float imageHeightPrint = e.Graphics.DpiY * imageToPrint.Height / imageToPrint.VerticalResolution;

e.Graphics.DrawImage(imageToPrint, e.MarginBounds.Left, yPos);

yPos += imageHeightPrint;

【问题讨论】:

    标签: c# .net graphics printing


    【解决方案1】:

    在剖析文档后,我自己找到了正确的解决方案。

    这一行:

    float imageHeightPrint = e.Graphics.DpiY * imageToPrint.Height / imageToPrint.VerticalResolution;
    

    应该改成这样:

    float imageHeightPrint = imageToPrint.Height / 
                             imageToPrint.VerticalResolution * 100;
    

    我错过的最大的事情是印刷高度应该以百分之一英寸为单位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 2018-06-10
      • 2021-11-30
      • 2018-11-12
      • 2020-06-19
      • 2012-06-16
      • 1970-01-01
      相关资源
      最近更新 更多