Page 1 of 1

Image bloat in RTF files

Posted: Mon Aug 13, 2012 7:43 am
by TheSteven
Hi Sergey,
Been having an issue with tRichView and RTF files containing embedded images. I did a little research and found the problem.

Problem:
TRichView
-RTFReadProperties
when the ExtractMetafileBitmaps property is set to False
the tRichview component will use the original image embedded in the RTF but if the WMF image is missing from the RTF it then fails to retrieve the image (even though it wouldn't use WMF anyway).
This should not be the case, it should still retrieve the original image. For those of us using RTFs with embedded images fixing this would reduce the files size of the RTF files significantly.

Background:
On a PC when you add images to an RTF file, the image gets stored in the RTF file as a WMF, uncompressed. Which cause the file size to jump up dispportionally to the original image size.

You can turn off the creation of the WMF in MS Word by changing a registry value as described here:
Document file size increases with EMF, PNG, GIF, or JPEG graphics in Word
This fixes the bloating problem with images in RTF files but due to the issue mentioned above tRichView has issues.

Other references:
How to reduce size of RTF with embedded images?

Best regards,
Steven

Posted: Mon Aug 13, 2012 7:50 am
by TheSteven
BTW
The RTF files are created using MS Office 2010
and tRichView is the latest 2012-Aug-12 release.

Posted: Tue Aug 14, 2012 12:44 pm
by Sergey Tkachenko
ExtractMetafileBitmaps affects only reading metafiles. If this property is true and TRichView can extract a bitmap from a metafile, the image is loaded as TBitmap, otherwise it is loaded as TMetafile. In the both cases, the image is loaded.

Normally, MS Word saves raster images in RTF in two alternative representations. The first is a metafile, the second is a png or a jpeg image. If possible, TRichView reads the second image. However, TRichView does not use PNG images by default.
Call RV_RegisterPngGraphic(TPngImage) one time before the first loading
(if you use Delphi 2009+; if you use older version, install TPngObject by Gustavo Huffenbacher Daud from http://www.trichview.com/resources/thir ... gimage.zip and call RV_RegisterPngGraphic(TPngObject).

Posted: Tue Aug 14, 2012 5:20 pm
by TheSteven
Ok so you are saying that if the ExtractMetafileBitmaps property is set to False - that it does not load the bitmap but only loads the MetaFile?

The original image, as far as I'm aware, that MS Word is inserting into the RTF is a bitmap. So if I disable MS Word from creating the MetaFile image what format is the image in the RTF?

What I am seeing is that if I disable the WMF from being created in the RTF document that tRichView can not load the image regardless of how the ExtractMetafileBitmaps property is set.

Posted: Wed Aug 15, 2012 7:25 am
by Sergey Tkachenko
What I am seeing is that if I disable the WMF from being created in the RTF document that tRichView can not load the image regardless of how the ExtractMetafileBitmaps property is set.
Please reread my answer about PNG.

Posted: Thu Aug 16, 2012 1:56 am
by TheSteven
Thanks, works now.

Note for anyone else if you have Delphi 2009+
RV_RegisterPngGraphic(TPngImage)
requires
Uses: PNGImage, CRVData