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

Exporting images in TX Text Control

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.1
Released:March 20, 2001
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic
Download code:exporting_images.zip Download [3.63 KB, ZIP]

One of the new features of TX Text Control v10 is the image export. The format of the exported images and whether the image files should be saved inline or to separate files can be set programmatically or by the end-user. Saving to separate files is ideally suited for applications that rely on HTML.

This brief code snippet illustrates how the new export features can be used. Our finished application looks like this:

Download the source code below and start the sample application. Click on the menu "Image -> Insert", browse for an image of your choice and click on "Open". Note here that all supported images are displayed. It is not necessary to select JPGs or PNGs explicitly. We will be discussing more on this later.

The image is then inserted. Activate the image by clicking on it. Then go to the image menu and select "Image Settings". A dialog box will open and you will be able to set the export properties of the image. The image is embedded as default and saved in TX Text Control's internal format.

Here is the code that enables the dialog settings:

  1. Private Sub Form_Activate()
  2.  
  3. optEmbed.Value = (Form1.TXTextControl1.ImageSaveMode = 1)
  4. optExport.Value = (Form1.TXTextControl1.ImageSaveMode = 0)
  5.  
  6. If (Form1.TXTextControl1.ImageExportFormat > 0) Then
  7. cboFileFormats.ListIndex = Form1.TXTextControl1.ImageExportFormat - 1
  8. End If
  9.  
  10. End Sub

Using the ImageSaveMode property, we can determine whether the image is saved to a new file or be embedded. Using ImageExportFormat, we can determine the current format. This is an index to the combo box items of image types that is created when the program starts. Following is the code to do this:

  1. Private Sub Form_Load()
  2.  
  3. ' Fill combo box with available image file formats
  4. Dim FileFormats As String
  5. FileFormats = Form1.TXTextControl1.ImageExportFilters
  6.  
  7. While Len(FileFormats)
  8. n = InStr(FileFormats, "|") ' find first occurence of "|" character
  9. n = InStr(n + 1, FileFormats, "|") ' find second occurence of "|" character
  10. If n Then
  11. cboFileFormats.AddItem Left(FileFormats, n - 1)
  12. FileFormats = Right(FileFormats, Len(FileFormats) - n)
  13. Else
  14. cboFileFormats.AddItem FileFormats
  15. FileFormats = ""
  16. End If
  17. Wend
  18.  
  19. End Sub

The ImageExportFilters method returns a string that holds the installed export filter formats, formatted for a common dialog that we can apply to the "Filter" parameter.

Now we need to parse the string to get the actual formats. These are stored in the combo box.

Similarly, we build up a string called sExportFilters as mentioned above that holds all formats separated by a semicolon in the "Load" routine of Form1. This string can be applied to the "Filter" parameter of a common dialog and thus all supported formats are displayed at once. Here is the code:

  1. Private Sub Form_Load()
  2.  
  3. Dim nPos As Integer
  4. Dim nLength As Integer
  5. Dim sTemp As String
  6.  
  7. sTemp = TXTextControl1.ImageExportFilters
  8.  
  9. While (Len(sTemp) <> 0)
  10. nPos = InStr(1, sTemp, "|")
  11. If (Len(sExportFilters) <> 0) Then sExportFilters = sExportFilters + ";"
  12.  
  13. sExportFilters = sExportFilters + Mid(sTemp, nPos + 1, 5)
  14.  
  15. sTemp = Mid(sTemp, nPos + 7)
  16. Wend
  17.  
  18. End Sub

As ever, we would be delighted to help you with this example. Please post your questions and requests for support into the TX Text Control Support Forum.

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