We are frequently asked why the filesize of documents containing images (BMP and WMF) grows when they are exported to Microsoft Word or RTF formats.
The answer is quite simple:
Images might be exported as a BMP or WMF files, which are typically built from uncompressed data.
Reducing the filesize of documents containing images is equally simple:
TX Text Control .NET for Windows Forms supports image export to external files, using compressed formats, such as JPG or PNG. Developers often are not aware that the image format can be also specified, if the images are embedded in the document itself.
The SaveMode property of the Image class specifies whether the image should be exported or embedded in the document.
The ExportFilterIndex, on the other hand, specifies the format of the image. Possible formats are: BMP, WMF, PNG or JPG.
In the following VB.NET sample, the resulting document size clearly demonstrates the effect of setting an appropriate image format:
BMP -> 151 KB WMF -> 53 KB PNG -> 56 KB JPG -> 13 KB
The sample shows how to change every image format in a document. The ComboBox receives all image formats from the Images.ExportFilters property.
For Each image As TXTextControl.Image In TextControl1.Images image.ExportFilterIndex = ComboBox1.SelectedIndex + 1 image.SaveMode = TXTextControl.ImageSaveMode.SaveAsData Next Dim fileFormatIndex As String = ComboBox1.SelectedIndex + 1 TextControl1.Save("test_" + fileFormatIndex + ".rtf", TXTextControl. StreamType.RichTextFormat)