在Open XML裏使用了English Metric Units(EMUs)來做爲度量單位。好比this
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),並沒給出具體的解釋。code
wikipedia裏關於Office_Open_Xml裏關於DrawingML裏面對EMUs有一段定義orm
http://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingMLxml
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/分辨率ip
代碼以下ci
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);