[英]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.