Convert Pixels to Points
Solution 1:
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.
Solution 2:
Try this if your code lies in a form:
Graphics g = this.CreateGraphics();
points = pixels * 72 / g.DpiX;
g.Dispose();
Solution 3:
Starting with the given:
- There are 72 points in an inch (that is what a point is, 1/72 of an inch)
- on a system set for 150dpi, there are 150 pixels per inch.
- 1 in = 72pt = 150px (for 150dpi setting)
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