[英]DPI Graphics Screen Resolution Pixels 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
因此,通过Windows系统DPI设置可以使96像素变成1英寸。
但是,实际上,这确实取决于您的显示器尺寸。
对于设置为1600 x 1200分辨率的19英寸LDC监视器,请使用毕达哥拉斯定理可帮助计算监视器的像素密度:
[Screen DPI] = Math.Sqrt(Math.Pow(1600, 2) + Math.Pow(1200, 2)) / 19
使用这些数据,我编写了一个静态工具,现在将其保存在所有项目的Tools类中:
/// <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;
}
我希望其他人可以从这个漂亮的小工具中受益。
对于屏幕:像素= Graphics.DpiY *点/ 72
对于您的问题主题中提到的打印机,默认情况下映射为1'pixel'== 0.010英寸。 这非常接近默认的视频dpi,即每英寸96点,使纸上副本的尺寸与显示器上的尺寸相同。
制作表格的屏幕截图并将其打印是一个坏主意。 打印机具有更高的分辨率,典型值为600 dpi。 当屏幕上的每个像素变成纸上的6x6斑点时,打印输出看起来将呈颗粒状。 对于抗锯齿的文字尤其引人注目且难看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.