# Pixel to centimeters.

### Question

•  Does anyone know of a function to convert pixel to centimeter?
Wednesday, November 07, 2012 1:45 PM

• Hi,

what do you mean by "pixel"?

Do you have an image (jpg/png or something like that)? Then the image has information about the resolution (e. g. 300 dpi) which you have to use to calculate the images size in centimeters.

Do you talk about the WPF units like <Border Width="100" ...>? Then the 'WPF-resolution' is 96 dpi and you can calculate it like above.

Do you talk about monitor pixels? Then I don't know of a way to calculate it reliable. I've seen so many devices with the same 'size (e. g. 24inches) and different measurements, that there is no way of telling the true resolution.

Did you mean something else? Ask again and be a bit more precise.

Hope it helped already.

Cheers
Jürgen

NB: 96 dpi => 96/2.54 = 37.8 dots per cm => the Border from above has a width of 2.646 cm

Wednesday, November 07, 2012 4:57 PM
• WPF uses pixels that are DPI(device independent). As Jürgen has told you, 1 pixel = 1/96 inches. This does not mean that you can draw border using Width="1" and when you bring out ruler, you will actually measure and it IS 1/96 inches on a monitor. No. This depends on monitor and operating system settings. (UserDPI).

The easiest way to exploit Microsoft claim that 1 pixel = 1/96 inches is to set "native resolution" of you rmonitor and go to the user settings and put correct DPI. It should match physical DPI.

Say your native resolution is 1600x1200 and physical size is 17 x 12.75 inches, then you can calculate physical dpis : PhysicalDPIHorizontal = 1600/17 = 94 , PhysicalDPIVertical = 1200/12.75=94. Use custom DPI "94" and voila.

Wednesday, November 07, 2012 5:23 PM

### All replies

• Hi,

what do you mean by "pixel"?

Do you have an image (jpg/png or something like that)? Then the image has information about the resolution (e. g. 300 dpi) which you have to use to calculate the images size in centimeters.

Do you talk about the WPF units like <Border Width="100" ...>? Then the 'WPF-resolution' is 96 dpi and you can calculate it like above.

Do you talk about monitor pixels? Then I don't know of a way to calculate it reliable. I've seen so many devices with the same 'size (e. g. 24inches) and different measurements, that there is no way of telling the true resolution.

Did you mean something else? Ask again and be a bit more precise.

Hope it helped already.

Cheers
Jürgen

NB: 96 dpi => 96/2.54 = 37.8 dots per cm => the Border from above has a width of 2.646 cm

Wednesday, November 07, 2012 4:57 PM
• WPF uses pixels that are DPI(device independent). As Jürgen has told you, 1 pixel = 1/96 inches. This does not mean that you can draw border using Width="1" and when you bring out ruler, you will actually measure and it IS 1/96 inches on a monitor. No. This depends on monitor and operating system settings. (UserDPI).

The easiest way to exploit Microsoft claim that 1 pixel = 1/96 inches is to set "native resolution" of you rmonitor and go to the user settings and put correct DPI. It should match physical DPI.

Say your native resolution is 1600x1200 and physical size is 17 x 12.75 inches, then you can calculate physical dpis : PhysicalDPIHorizontal = 1600/17 = 94 , PhysicalDPIVertical = 1200/12.75=94. Use custom DPI "94" and voila.

Wednesday, November 07, 2012 5:23 PM