Hardik Lotiya
Hardik Lotiya

Reputation: 370

Centimeters to Pixels Conversion

how to convert 1 cm to ?px

this conversion used in html parser

% conversion is -> (allToPx[0]) * 16)/100) px

pt conversion is -> (allToPx[0]) * 16)/12) px

em conversion is -> (allToPx[0]) * 16)/1) px

but how to convert in cm ?

Upvotes: 1

Views: 2368

Answers (3)

ppeterka
ppeterka

Reputation: 20726

You have to figure out the pixel density for the display you work on. This might be drastically different. You have to get these data:

  • width of screen
  • height of screen
  • vertical pixels
  • horizontal pixels

Then you can calculate what the actual size of a given pixel vertically and horizontally...

But obtaining this kind of information is not always possible. You might have to use some platform dependant trickery to get these, if even possible... Also, you didn't specify what kind of UI library you use. That might be of help for us to be able give advice.

Upvotes: 3

Russell Gutierrez
Russell Gutierrez

Reputation: 1385

It would not be impossible to convert cm to px since they are not of the same unit types.

cm is an absolute length unit while px is a relative length unit

Its just like saying, "Can I convert kilos to hours?"

Use this as reference: http://msdn.microsoft.com/en-us/library/ms537660(v=vs.85).aspx

Upvotes: 1

kostja
kostja

Reputation: 61538

There is no cm conversion as the size of the elements in cm depends heavily on the screen density (pixels per inch or cm), which you can't access on most devices

Upvotes: 1

Related Questions