DPI图形屏幕分辨率像素WinForm PrintPageEventArgs
对于运行我的应用程序的任何显示器,Dpi点如何与像素相关?
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像素的长度吗?
DPI字面意思是“每英寸点数” – 其中点==像素。 所以要确定1200像素的长度:
int inchesLong = (1200 / e.Graphics.DpiX);
我意识到已经有几个月了,但在阅读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 x 1200分辨率的19英寸LDC显示器,使用毕达哥拉斯定理有助于计算显示器的像素密度:
[Screen DPI] = Math.Sqrt(Math.Pow(1600, 2) + Math.Pow(1200, 2)) / 19
使用这些数据,我写了一个静态工具,我现在保存在我所有项目的Tools类中:
/// /// Calculates the Screen Dots Per Inch of a Display Monitor /// /// Size, in inches /// width resolution, in pixels /// height resolution, in pixels /// double presision value indicating the Screen Dots Per Inch 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; }
我希望其他人可以使用这个漂亮的小工具。
对于屏幕:pixels = Graphics.DpiY * points / 72
对于问题主题中提到的打印机,默认情况下,映射为1’像素’== 0.010英寸。 这非常接近每英寸96点的默认videodpi,使得复印在纸上的尺寸与显示器上显示的大小相同。
制作表单的屏幕截图并打印它们是一个坏主意。 打印机具有更高的分辨率,典型的是600 dpi。 当屏幕上的每个像素在纸上成为6×6 blob时,打印输出将呈现颗粒状。 对于抗锯齿文本尤其引人注目且难以理解。