Embedding images in various formats
Blogged by Björn Meyer on April 06, 2005 and tagged with Samples, Image, .NET.
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 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)
The working VB.NET sample can be downloaded here.


Posted by Scott on Monday, April 11, 2005 at 22:25:35:
Posted by Björn Meyer on Tuesday, April 12, 2005 at 15:07:04:
Posted by Scott on Friday, September 23, 2005 at 07:57:44:
Posted by Björn Meyer on Friday, September 23, 2005 at 09:51:35:
Posted by Scott on Wednesday, September 28, 2005 at 18:41:06:
Posted by Sabrina on Tuesday, January 22, 2008 at 15:07:19:
Posted by Igal Foigel on Saturday, May 16, 2009 at 17:27:44:
Posted by Björn Meyer on Monday, May 18, 2009 at 09:21:48: