Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Embed or export images in various formats

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:Visual Basic .NET
Version:1.0
Released:April 07, 2005
Last modified:January 11, 2008
Requirements:TX Text Control .NET with Visual Basic .NET
Download code:tx_sample_dotnet_export.zip Download [28.42 KB, ZIP]
Click to enlarge

TX Text Control offers two possibilities to save images in documents: embedded or as external image files. Possible image formats are BMP, WMF, PNG and JPG. These image export filters are shipped with every version of TX Text Control.

Sometimes it is necessary to keep files small in order to save hard disk space or bandwidth, if the document is sent by email. In this case, it is often desirable to offer end users the option of converting images in the document to a compressed format such as JPG. This sample shows how to convert every image in the document to a specified format.

There are two important properties that can be used to specify the format and way the image is included in the document:

  • Image.ExportFilterIndex
  • Image.SaveMode

We use the Images collection to iterate through all images in the document to specify the new image export format. Additionally, the SaveMode property determines whether the image should be embedded or exported.

  1. For Each image As TXTextControl.Image In TextControl1.Images
  2. image.ExportFilterIndex = ComboBox1.SelectedIndex + 1
  3. If RadioButton1.Checked = True Then
  4. image.SaveMode = TXTextControl.ImageSaveMode.SaveAsData
  5. Else
  6. image.SaveMode = TXTextControl.ImageSaveMode.SaveAsFileReference
  7. End If
  8. Next

In this sample, we used a ComboBox to select the image format. This list can be easily filled with the Images.ExportFilters property which returns all available filters. The following code fills this ComboBox with the appropriate content.

  1. Dim imageFormats() As String
  2. imageFormats = TextControl1.Images.ExportFilters.Split("|")
  3.  
  4. For i As Integer = 0 To 7 Step 2
  5. ComboBox1.Items.Add(imageFormats(i))
  6. Next
  7.  
  8. ComboBox1.SelectedIndex = 0

As ever, we would be delighted to help you with this sample. Please contact the Support Department, if you have any questions about this sample. The sample requires Visual Studio 2003 and at least a TX Text Control .NET 11.0 trial version.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place