0

I hooked into the question located at "Replace image in word doc using OpenXML". I noticed that there are several ImagePartType types. Is there any easy "built in" way to determine which type a specific image should be other than going by it's extension? The ImagePartType enum is also used in PowerPoint as is alot of the WordProcessingML structures.,

For instance, ImagePartType.Bmp on image1.bmp
ImagePartType.Emf on image1.emf
ImagePartType.Gif on image1.gif ImagePartType.Icon on image1.ico ImagePartType.Jpeg on image1.jpeg or image1.jpg ImagePartType.Pcx on image1.pcx
ImagePartType.Png on image1.png
ImagePartType.Tiff on image1.tiff or image1.tif
ImagePartType.Wmf on image1.wmf

Community
  • 1
  • 1
General Redneck
  • 1,240
  • 2
  • 13
  • 28
  • First off, welcome to stackoverflow! Secondly, why can't you go by file extension? If the data is named wrong, then you should alert the user in some fashion. – Richard J. Ross III Oct 12 '10 at 01:11
  • Actually no particular reason. I was mostly looking to see if there was a more "Official" way of doing things. And thanks for the warm welcome – General Redneck Oct 12 '10 at 01:23
  • Additionally, I'm grabbing items from an URL. It's part of an API. It's kinda hard to predict user content. I have a feeling that PowerPoint won't care too much, if worse comes to worse I can check mime type or something similar. – General Redneck Oct 12 '10 at 01:35
  • 1
    I haven't checked how/whether this is made available in the API, but the "correct" way should be to check the [Content_Types].xml part in the OpenXML package. – Dirk Vollmar Nov 16 '10 at 23:18
  • Tis over a year since I looked at this but decided it would be best to come back to it. Content_types don't have anything with the "Media" in there, so I ended up just checking the extension. – General Redneck Jun 07 '11 at 17:02

1 Answers1

0

There is not - because you can have filename.png which is actually a bmp file and it all works fine. The only way to know for sure is to read the actual bitmap file and see what format it is in.

You can do this either by loading it into an Image class, or just read the first couple of bytes and look for the signature of each of the formats.

David Thielen
  • 28,723
  • 34
  • 119
  • 193