English Metric Units and Open XML

Emu
[image by blmurch]

In this article, you’ll find out how English Metric Units (or EMUs) are related to the Open XML format. So what are English Metric Units? They are … actually, I have no idea what they are. Here’s the best answer I could find on EMUs. And there’s the Open XML explanation on EMUs in Wikipedia.

I stumbled upon EMUs because I was trying to create an Excel spreadsheet using the Open XML format. The task require the addition of an image in one of the Excel sheets. You have no idea how much code I needed to write just to include one image. (I’ll tell you about that in another article. Let’s focus on EMUs here.)

Basically, there’s no unifying unit, no “one ring to bind them all”: centimetres, inches and points. So they used a new unit of measurement to represent the dimensions of an image. *sigh*

Anyway, while searching for how to convert pixels to EMUs, I stumbled upon 2 articles on StackOverflow: Pixel to Centimetre and Pixel to Point.

From the Wikipedia article, there are 914400 EMUs per inch, and there are 96 pixels to an inch. Therefore, I figured the pixel to EMU formula is

EMU = pixel * 914400 / 96

There’s a flaw, in that the dots per inch (DPI) may be different for different monitors. For example, there could be 72 pixels in an inch. The best I could do is to assume that, the image created with one monitor, will be used on another monitor with the same DPI. Thus:

EMU = pixel * 914400 / Resolution

Here’s some code to visualise that:

Bitmap bm = new Bitmap("yourimage.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);

There, now you know how English Metric Units are related to Open XML formats.

There’s updated material and source code, together with more information on how to work with Open XML. Click here to find out more.

P.S. English Metric Units have no relation to emus. Other than their (unfortunate?) acronym being exactly the same as the name of the Dromaius novaehollandiae

Sorry, comments are closed, but you can contact me directly if you like.