How do Dpi Points relate to Pixels for any display my application is running on?
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);
}
}
Do I now have all of the information I need?
Can I use any of the information above to find out just how long 1200 pixels is?
I realize it has been a few months, but while reading a book on WPF, I came across the answer:
If using standard Windows DPI setting (96 dpi), each device-independent unit corresponds to one real, physical pixel.
Hence, 96 pixels to make an inch through the Windows system DPI settings.
However, this does, in reality, depend on your display size.
For a 19-inch LDC monitor set to a resolution of 1600 x 1200, use the Pythagoras theorem helps to calculate pixel density for the monitor:
Using this data, I wrote up a little static tool that I now keep in my Tools class of all my projects:
I hope others get some use out of this nifty little tool.