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

对于运行我的应用程序的任何显示器,Dpi Points如何与像素相关?

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字面上代表“Dots Per Inch” – 其中dot == pixels.所以要确定1200像素的长度:

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

转载注明原文:c# – DPI图形屏幕分辨率像素WinForm PrintPageEventArgs - 代码日志