A point (pt) is equal to 0.352778 millimeters, 0.0138889 inches, or 1.333 pixels.
Font size specifications may come in points or pixels where: 1 pixel (px) is usually assumed to be 1/96th of an inch. 1 point (pt) is assumed to be 1/72nd of an inch. Therefore 16px = 12pt.
Pixels and points are static measurements - they don't change based on other factors: 1 pixel is always 1 pixel and is the smallest piece of a screen that can display colours. 1 point is always 1 point and is an abstract unit, only having meaning when referenced in relation to other points.
There are 72 points per inch; if it is sufficient to assume 96 pixels per inch, the formula is rather simple:
points = pixels * 72 / 96
There is a way to get the configured pixels per inch of your display in Windows using GetDeviceCaps
. Microsoft has a guide called "Developing DPI-Aware Applications", look for the section "Creating DPI-Aware Fonts".
The W3C has defined the pixel measurement px
as exactly 1/96th of 1in regardless of the actual resolution of your display, so the above formula should be good for all web work.
Try this if your code lies in a form:
Graphics g = this.CreateGraphics();
points = pixels * 72 / g.DpiX;
g.Dispose();
Starting with the given:
If you want to find points (pt) based on pixels (px):
72 pt x pt
------ = ----- (1) for 150dpi system
150 px y px
Rearranging:
x = (y/150) * 72 (2) for 150dpi system
so:
points = (pixels / 150) * 72 (3) for 150dpi system
Assuming 96dpi is a huge mistake. Even if the assumption is right, there's also an option to scale fonts. So a font set for 10pts may actually be shown as if it's 12.5pt (125%).
WPF converts points to pixels with the System.Windows.FontSizeConverter. The FontSizeConverter uses the System.Windows.LengthConverter. The LengthConverter uses the factor 1.333333333333333333 to convert from points (p) to pixels (x): x = p * 1.3333333333333333
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With