English Metric Units and Open XML
在Open XML里使用了English Metric Units(EMUs)来作为度量单位。比如
public class Extent : OpenXmlLeafElement的cx和cy属性
<wp:extent cx="1828800" cy="1828800"/>
MSDN的解释:The cx attributes specifies that this object has a height of 1828800 EMUs (English Metric Units),并没给出具体的解释。
wikipedia里关于Office_Open_Xml里关于DrawingML里面对EMUs有一段定义
http://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML
A DrawingML graphic's dimensions are specified in English Metric Units (EMUs). It is so called because it allows an exact common representation of dimensions originally in either English or Metric units. This unit is defined as 1/360,000 of a centimeter and thus there are 914,400 EMUs per inch, and 12,700 EMUs per point.
1EMUs= 1/914400英寸
而我们在计算的时候,通常得到的是图片的像素,根据图片分辨率的不同,每一寸上的像素点事不同的。
所以 EMUS=像素*1914400/分辨率
代码如下
Bitmap bm = new Bitmap("image.jpg");
DocumentFormat.OpenXml.Drawing.Extents extents = new DocumentFormat.OpenXml.Drawing.Extents();
extents.Cx = (long)bm.Width * (long)((float)914400 / bm.HorizontalResolution);
extents.Cy = (long)bm.Height * (long)((float)914400 / bm.VerticalResolution);