简体   繁体   English

从C#中的像素计算英寸和厘米

[英]Calculate inches and centimeters from pixels in C#

I am working on a Productivity app and need to be able to calculate (in C#) inches and centimeters. 我正在开发一个Productivity应用程序,需要能够计算(以C#为单位)英寸和厘米。 Based on pixels, obviously. 基于像素,显然。

When you open Microsoft Word, and search through the Templates, you'll find, for example, business cards. 当您打开Microsoft Word并搜索模板时,您会发现,例如,名片。 And you'll see that their measurements are based upon inches and/or centimeters. 你会发现它们的测量值是以英寸和/或厘米为单位的。 How do they get those calculations when they're dealing only with pixels on a screen? 当他们只处理屏幕上的像素时,他们如何获得这些计算?

People generally say "blah blah you can't do that blah blah blah" but that's not true at all. 人们通常说“等等,你不能这样做等等等等”,但这根本不是真的。 I printed a sample business card, MS Word said it would be about 8"x4". 我打印了一张样本名片,MS Word表示它大约是8“x4”。 On the screen it was not that big but when it was printed onto paper it was exactly what it said. 在屏幕上它不是那么大,但当它被打印到纸上时,它正是它所说的。 So it can be done and I don't want to hear another person say "You cannot do that". 所以它可以完成,我不想听到另一个人说“你做不到”。

I think the conversion of pixels to centimeters depends on the DPI (dots per inch) of the media which is displaying the image. 我认为像素到厘米的转换取决于显示图像的媒体的DPI(每英寸点数)

Also the formula is simple for conversion ie, 该公式也很简单,即,

points = pixels * 72 / 96

since there 72 points per inch and 96 pixels per inch(you can assume) 因为每英寸72 点,每英寸96像素(你可以假设)

You may also check How do you convert pixels into centimeters? 您还可以查看如何将像素转换为厘米?

In truth, you don't convert pixels to cm. 实际上,您不会将像素转换为cm。 There is a little more information that is needed and without knowing exactly what it is that you want to do, it is difficult to address this completely. 需要更多信息,而不知道您想要做什么,很难完全解决这个问题。 There is a de facto norm of 300 DPI /PPI for printing (that is 300 / 2.54 pixels/cm). 印刷有300 DPI / PPI的事实上的标准(即300 / 2.54像素/ cm)。

A pixel is one of the colored dots on your computer screen that makes up both images and text (as well as all of the blank areas in between them). 像素是计算机屏幕上的一个彩色点,它构成图像和文本(以及它们之间的所有空白区域)。 Most computer screens display either 72 or 96 pixels per inch. 大多数计算机屏幕显示每英寸72或96像素。 Most printing is based on 300 pixels per inch (rarely 240 PPI). 大多数打印基于每英寸300像素(很少240 PPI)。

If you are asking about printing: If you want to make a 4 x 6 inch print on a 300 DPI (Dot Per Inch) printer you need your file to contain 1200 x 1800 pixels. 如果您要询问打印:如果要在300 DPI(每英寸点数)打印机上进行4 x 6英寸打印,则需要将文件包含1200 x 1800像素。 An 8 x10 printout will have to be 2400 x 3000 pixels. 8 x10打印输出必须为2400 x 3000像素。 In reality, most consumer printing systems will handle this conversion for you. 实际上,大多数消费者打印系统都会为您处理此转换。 You just tell the software what size print you want to make the software will "re size" your image to the correct dimensions. 您只需告诉软件您要使用什么尺寸的打印件,软件会将图像“调整”到正确的尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM