Share via


RichEdit 8.0 Image Support

Up until RichEdit 8.0, RichEdit’s native image support was limited to metafiles, enhanced metafiles, and simple images like bitmaps (bmp’s). If OLE (Object Linking and Embedding) had supported other types, such as jpg’s, png’s and gif’s, RichEdit would have supported them automatically. But OLE’s functionality was frozen years ago. RichEdit 5.0 added “blobs”, which are light-weight OLE-like objects that the RichEdit client, like OneNote, renders. These blobs allow OneNote to insert and render many kinds of images. More recently, Microsoft created the Windows Imaging Component (see also), which supports the most popular image formats and allows extensions. RichEdit 8.0 uses this component to provide image support for jpg’s png’s and gif’s. This blog post summarizes the capabilities and APIs to take advantage of this facility.

A number of facilities that ship in Office RichEdit’s are not available in the Windows 8 RichEdit mostly because there wasn’t time to test them thoroughly outside the Office environment and to document them properly. One such facility is the RichEdit blob. RichEdit 8 uses its own built-in implementation of the blob to store and render images using the Windows Imaging Component.

There are two ways to insert images into a classic RichEdit 8 instance (use Windows 8 msftedit.dll): the EM_INSERTIMAGE message and the TOM2 ITextRange2::InsertImage() method. In addition, you can insert images into a WinRT RichEditBox using the WinRT TOM Windows.UI.Text.ITextRange.InsertImage() method. The first two specify the image dimensions in HIMETRIC units (.01 mm = 2540/inch) and the WinRT method uses Device Independent Pixels (96/inch). For example, to have a 4”×3” image in a classic RichEdit instance, use a width of 4×2540 = 10160 and a height of 7620.

In addition to the height and width, the APIs have an ascent parameter, which is usually zero. It’s included in case the image contains text that should be aligned with the text base line. In the original blob implementation for OneNote, this was used (and still is) for aligning hand written images with the text baseline. It’s also useful for aligning images of mathematics with the text baseline. This second use is supported by the ITextServices2::TxGetNaturalSize2() to return the baseline of text images created using RichEdit. This facility is used in the Office Equation ribbon.

You can save files including images in the RTF file format. The images are saved via RichEdit’s blob extension to RTF. This uses the OLE \object destination with a RichEdit-specific type of \objblob1. Unfortunately this type is known only to RichEdit. It would be better to save it as a native RTF shape ({\*\shppict{\pict{…}}) so that Word and other programs could understand it. Also then RichEdit could support such images in Word-generated RTF files. Hopefully next time…

Comments

  • Anonymous
    October 24, 2012
    Hello! Thank you for your article! Can you suggest any automatic converters for rtf files with images? Or can you post an example how to create rtf file with images for winrt RichEditBox? Thank you!

  • Anonymous
    October 24, 2012
    The Windows 8 RichEdit stores images using its blob RTF. I could publish a spec for this RTF. It's similar to the standard image RTF, but has some extra control words and binary data. We plan to support the standard image RTF, but will continue to accept the blob image RTF. One way to create the image blob RTF is to insert an image into the RichEditBox and save the result as RTF. You'll see the various control words. Note that in the binary data, the image proper (that in a jpeg, png, gif, tiff, etc., file) starts with a header code. For jpeg that's FF D8 FF E0 ... For png it's 89 50 4e 47, etc. By looking for the header code, you can see where the blob binary data ends and the image data starts. The blob data is real binary, so you'll need a hex dump program to examine it. You can use the hex dump program to check out image files too. If you create your own blob RTF, it doesn't have to have real binary; just don't include the bin N control word. The binary data for standard image RTF for jpeg and png is a copy of what you'll find in the corresponding image file. So it starts with the header code. You can see this by inserting a jpeg or png into Word and saving it as RTF. Sorry this isn't a little easier!

  • Anonymous
    November 29, 2012
    RichEdit 5.0 added “blobs”, which are light-weight OLE-like objects that the RichEdit client, like OneNote, renders. After reading the article I'm wondering if this funcionality is in the stock RichEdit5 control included with windows, I need something like this but I can't find it in the documentation (other than the OLE objects that I would rather avoid).

  • Anonymous
    December 01, 2012
    The blob facility ships with the  Office versions of RichEdit starting with RichEdit 5 (Office 2003). It uses undocumented interfaces ITextMarkContainer and ITextBlob (a callback interface). Thanks for your feedback; it shows that there's outside interest in exposing such functionality. Also this functionality will live on into the Windows RT era, whereas it's not likely that OLE will.

  • Anonymous
    February 10, 2014
    Is there a way to get the file name removed under the inserted bmp picture for vs2008, with win32 SDK v6.0a, please?  I need my codes works also on Windows XP. My codes here: msdn.microsoft.com/.../dd387916%28v=vs.85%29.aspx

  • Anonymous
    April 13, 2016
    Is RichEdit 8 landing soon ? I

    • Anonymous
      April 18, 2017
      Shipped with Windows 8. Windows 10 has an enhanced version...