Convert Size from CMs to Pixels

Navigation:  »No topics above this level«

Convert Size from CMs to Pixels

Previous pageReturn to chapter overviewNext page

Internally our barcode Win32 DLL converts the value of barcode related size such as bar height and narrow bar width from centimeters to pixels based on device resolution, round up or round down float pixel value to the nearest integer.

 

The centimeter to pixel conversion formula is :

size_in_pixels = size_in_centimeters * device_resolution / 2.54

 

For example, if you render barcode on computer screen and the screen resolution is 96dpi.

 

(1) If bar height is 1.5 CMs,  size_in_pixels = 1.5 * 96 / 2.54 = 56.6929, round up 56.6929 to 57, so actual bar height is 57 pixels.

 

(2) If bar height is 1.52 CMs,  size_in_pixels = 1.52 * 96 / 2.54 = 57.4488, round down 57.4488 to 57, so actual bar height is 57 pixels.

 

(3) If bar height is 1.54 CMs,  size_in_pixels = 1.54 * 96 / 2.54 = 58.2047, round down 58.2047 to 58, so actual bar height is 58 pixels.

 

Different bar height values might end up with same bar height in pixels due to performing rounding operations, same rounding operation is applied to narrow bar width conversion.