Extract images from Windows EMF during EnumEnhMetaFile parse?
-
Friday, April 13, 2012 9:45 PM
A program I am modifying converts EMF files to a different format (SVG). It does this with EnumEnhMetaFile() which calls the program's parsing routine for each record of the EMF. That works great for the vector stuff. However, it also needs to be able to pull out a bitmap when it hits an EMR_STRETCHDIBITS. (The final target is actually a base64 encoded PNG, but the sticking point is grabbing the Bitmap.) Does Microsoft provide a function somewhere for pulling out an image at this point? The inverse operation, adding a bitmap to the EMF, is abitmap.Draw, what I need is some sort of abitmap.Read that can operate from within the EnumEnhMetaFile data processing.
Note, I did find CreateDIBitmap which brings up another issue - that makes a Bitmap handle, and while Bitmaps have a Save method that may be used with an encoder (so as to write the PNG to a file or memory, as an intermediate step) the Bitmap handle seems not to support this.
I do not want to render the EMF into a bitmap, I want the original bitmap that is stored in the EMF. (It is possible that the resolution of the bitmap in the EMF is greater than that of the desktop.) The method used must work on Windows XP and up, but need not work on anything earlier than that.
Thank you.
All Replies
-
Monday, April 16, 2012 10:37 AMModerator
The only way I can find the clue to help you is the EMRSTRETCHDIBITS.iUsageSrc, it will return a BITMAPINFO , and its bmiHeader, the BITMAPINFOHEADER's fields will show you if the record you retrieved out is PNG.
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
Monday, April 30, 2012 1:45 AM
Based on the handle from CreateDIBitmap, create one GDI+ bitmap http://msdn.microsoft.com/en-us/library/ms536314(v=vs.85).aspx, then use Image.Save http://msdn.microsoft.com/en-us/library/ms535407(v=vs.85).aspx to save it as a local file
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Regards,
Jacky Wu
Microsoft Online Community Support


