←Select platform

DefaultEncoding Property

Indicates which encoding should be used when loading text files that do not contain a byte-order mark (BOM).
public CodecsTxtEncoding DefaultEncoding { get; set; } 
Public Property DefaultEncoding As CodecsTxtEncodingean 
@property (nonatomic, assign) LTCodecsTxtEncoding defaultEncoding; 
public CodecsTxtEncodingean isDefaultEncoding() 
public void setDefaultEncoding(CodecsTxtEncodingean DefaultEncoding) 
   property CodecsTxtEncoding^ DefaultEncoding 
      CodecsTxtEncoding^ get() 
      void set(CodecsTxtEncoding^ value) 

Property Value

This property is used only when loading a text file whose encoding is not specified by a byte-order mark (BOM). If the file contains a BOM, this property is ignored.

The value determines how the data contained in the file should be interpreted (Auto, ANSI, Unicode).

Note that files containing ANSI text will load properly ONLY on computers that use the same code page as the computer which saved the file. For example, an ANSI file contains non-ASCII characters (eg: £) and is saved using ANSI encoding on a computer with US/Wester Europe code page (1252). If you load the file on a computer with another code page (say 1250), the £ will be loaded as Ł.

See https://en.wikipedia.org/wiki/Windows-1250 for other characters that might be different in these code pages. The differences might be even larger if you try to load it on computers with non-latin code pages (eg: Arabic, Asian, Russian, etc).

In conclusion, it is far better to save text files as Unicode with a BOM and avoid having to use this property.

using Leadtools; 
using Leadtools.Codecs; 
// This C# example shows you how to load a file called "Ansi.txt" that contains ANSI text.  
public static void CodecsTxtLoadOptionsDefaultEncoding_Example() 
	using (RasterCodecs codecs = new RasterCodecs()) 
		string srcFile = @"Ansi.txt"; 
		using (CodecsImageInfo info = codecs.GetInformation(srcFile, false)) 
			if (!info.HasBom) 
				codecs.Options.Txt.Load.DefaultEncoding = CodecsTxtEncoding.Ansi; /* Load as Ansi. Here you can bring up a message box asking the user to select the encoding */ 
			codecs.Options.Load.AllPages = true; 
			using (RasterImage image = codecs.Load(srcFile)) 
				codecs.Save(image, srcFile + ".tif", RasterImageFormat.TifLzw, 0); 

Target Platforms

Help Version 21.0.2021.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly