public CodecsTxtEncoding DefaultEncoding { get; set; }
@property (nonatomic, assign) LTCodecsTxtEncoding defaultEncoding;
public CodecsTxtEncoding isDefaultEncoding()
public void setDefaultEncoding(CodecsTxtEncoding DefaultEncoding)
public:
property CodecsTxtEncoding^ DefaultEncoding
{
CodecsTxtEncoding^ get()
void set(CodecsTxtEncoding^ value)
}
DefaultEncoding # get and set (CodecsTxtLoadOptions)
The default value is Auto
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/Western 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;
using Leadtools.ImageProcessing.Core;
using Leadtools.Pdf;
// This C# example shows you how to load a file called "Ansi.txt" that contains ANSI text.
public 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);
}
}
}
}
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.MinMaxBitsCommand;
// This C# example shows you how to load a file called "Ansi.txt" that contains
// ANSI text.
public void codecsTxtLoadOptionsDefaultEncodingExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
String srcFile = combine(LEAD_VARS_IMAGES_DIR, "Example.txt");
CodecsImageInfo info = codecs.getInformation(srcFile, false);
if (!info.hasBom())
codecs.getOptions().getTxt().getLoad().setDefaultEncoding(CodecsTxtEncoding.ANSI); // Load as Ansi. Here you
// can bring up a message
// box asking the user to
// select the encoding //
codecs.getOptions().getLoad().setAllPages(true);
RasterImage image = codecs.load(srcFile);
codecs.save(image, srcFile + ".tif", RasterImageFormat.TIFLZW, 0);
assertTrue("File unsuccessfully saved to " + srcFile + ".tif", (new File(srcFile + ".tif")).exists());
System.out.printf("File successfully saved to %s%n", srcFile + ".tif");
image = null;
info = null;
codecs = null;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document