Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将图像的像素高度转换为图形对象使用的打印大小_C#_.net_Graphics_Printing - Fatal编程技术网

C# 将图像的像素高度转换为图形对象使用的打印大小

C# 将图像的像素高度转换为图形对象使用的打印大小,c#,.net,graphics,printing,C#,.net,Graphics,Printing,作为我的应用程序打印过程的一部分,我正在尝试打印一个缩小到指定宽度的图像列表,并将一个图像置于另一个图像的下方。问题是我无法理解如何将图像的像素高度转换为图形对象在打印期间使用的单位高度。如何正确计算imageHeightPrint变量 此代码段是图像打印循环的一部分,用于缩小图像并计算其高度和下一图像的位置 Image image = Image.FromStream(imageStream); // Get proportional correct height int imageHeig

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

此代码段是图像打印循环的一部分,用于缩小图像并计算其高度和下一图像的位置

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;

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

这一行:

float imageHeightPrint = e.Graphics.DpiY * imageToPrint.Height / imageToPrint.VerticalResolution;
应改为:

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

我错过的最大一件事是打印的高度应该是百分之一英寸。

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

这一行:

float imageHeightPrint = e.Graphics.DpiY * imageToPrint.Height / imageToPrint.VerticalResolution;
应改为:

float imageHeightPrint = imageToPrint.Height / 
                         imageToPrint.VerticalResolution * 100;
我错过的最大一件事是印刷品的高度应该是百分之一英寸