DPI图形屏幕分辨率像素WinForm PrintPageEventArgs

问题描述:

Dpi点与我的应用程序正在运行的任何显示器的像素有关吗?DPI图形屏幕分辨率像素WinForm PrintPageEventArgs

int points; 
Screen primary; 

public Form1() { 
    InitializeComponent(); 
    points = -1; 
    primary = null; 
} 

void OnPaint(object sender, PaintEventArgs e) { 
    if (points < 0) { 
    points = (int)(e.Graphics.DpiX/72.0F); // There are 72 points per inch 
    } 
    if (primary == null) { 
    primary = Screen.PrimaryScreen; 
    Console.WriteLine(primary.WorkingArea.Height); 
    Console.WriteLine(primary.WorkingArea.Width); 
    Console.WriteLine(primary.BitsPerPixel); 
    } 
} 

我现在是否拥有我需要的所有信息?

我可以使用上面的任何信息来找出1200像素是多长时间?

+0

注意:一旦我学会了如何通用地显示我的表单,表单上的数据将被发送到打印机 - 因此标题中的PrintPageEventArgs。 – jp2code 2011-02-25 20:05:48

我意识到它已经几个月了,但是在读一本书,WPF,我通过这个答案来了:

如果使用标准的Windows DPI设置(96 DPI),每一个与设备无关的单位对应一个真实的物理像素。

[Physical Unit Size] = [Device-Independent Unit Size] x [System DPI] 
        = 1/96 inch x 96 dpi 
        = 1 pixel 

因此,96像素可以通过Windows系统的DPI设置来制作一英寸。

但是,这实际上取决于您的显示器尺寸。

对于设置为1600×1200分辨率的19英寸LDC显示器,使用毕达哥拉斯定理有助于计算像素密度显示屏:

[Screen DPI] = Math.Sqrt(Math.Pow(1600, 2) + Math.Pow(1200, 2))/19 

利用这些数据,我写了一个小静工具,我现在请我的工具类我所有的项目:

/// <summary> 
/// Calculates the Screen Dots Per Inch of a Display Monitor 
/// </summary> 
/// <param name="monitorSize">Size, in inches</param> 
/// <param name="resolutionWidth">width resolution, in pixels</param> 
/// <param name="resolutionHeight">height resolution, in pixels</param> 
/// <returns>double presision value indicating the Screen Dots Per Inch</returns> 
public static double ScreenDPI(int monitorSize, int resolutionWidth, int resolutionHeight) { 
    //int resolutionWidth = 1600; 
    //int resolutionHeight = 1200; 
    //int monitorSize = 19; 
    if (0 < monitorSize) { 
    double screenDpi = Math.Sqrt(Math.Pow(resolutionWidth, 2) + Math.Pow(resolutionHeight, 2))/monitorSize; 
    return screenDpi; 
    } 
    return 0; 
} 

我希望别人得到一些使用了这个漂亮的小工具。

DPI字面意思是“每英寸点数” - 其中dots ==像素。因此,要确定1200个像素多久是:

int inchesLong = (1200/e.Graphics.DpiX); 
+0

视频dpi设置永远不会准确。无论显示器尺寸如何,它们都固定为96或120或144。 – 2011-02-25 20:17:07

+0

@Hans不正确。例如,我测试了192DPI的应用程序。它确实看起来很时髦,但它的尺度很好! – 2011-02-25 20:34:55

+0

@大卫 - 你买了另一台显示器来匹配那个dpi设置吗?要求英制尺寸相同。 – 2011-02-25 20:40:43

对于屏幕:像素= Graphics.DpiY *点/ 72

对于打印机,在你的问题受试者提到的,映射是1“像素” =默认= 0.010英寸。这非常接近每英寸96点的默认视频dpi,使得纸张的副本大小与您在显示器上看到的大小相同。

制作表单并打印它们的屏幕截图是一个坏主意。打印机具有更高的分辨率,典型值为600 dpi。当屏幕上的每个像素成为纸上的6x6斑点时,打印输出会看起来很粗糙。对于反锯齿文本尤其显着和富有感染力。

+0

实际上,表单只是在将数据发送到打印机之前呈现数据的“打印预览”。该项目应将所有数据绘制到表单中,以便将其发送到打印机。清除泥浆? :) – jp2code 2011-02-25 20:45:40

+1

确实很浑浊。使用PrintPreviewDialog,无需工作。 – 2011-02-25 20:48:29

+0

但是,最先出现鸡还是鸡蛋?大声笑 - 我必须绘制对象到SOMETHING,然后才能使用MS的PrintPreviewDialog ...除非我错过了一些东西。 – jp2code 2011-02-25 21:08:30