←Select platform

LoadOptions(string) Method

Summary

Loads the options into this RasterCodecs from a disk file.

Syntax

C#
VB
C++
public void LoadOptions( 
   string fileName 
) 
Public Overloads Sub LoadOptions( _ 
   ByVal fileName As String _ 
)  
public: 
void LoadOptions(  
   String^ fileName 
)  

Parameters

fileName
A String that contains the name of a disk file containing the options to load

Remarks

The RasterCodecs options can be easily saved to a disk or stream using SaveOptions(string fileName) or SaveOptions(Stream stream) and then loaded back into the same or a different RasterCodecs object using LoadOptions(string fileName) or LoadOptions(Stream stream).

Saving and loading the options is handy for situations where a RasterCodecs with specialized options other than the default is used. For example, in a server application as demonstrated by the example.

The options are saved in a standard XML file (with UTF-8 encoding) in the following format:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<leadtools_raster_codecs> 
  <options> 
     <option FullPropertyName="value" /> 
  </options> 
</leadtools_raster_codecs> 

FullPropertyName is the exact .NET property name of the options as accessed by the RasterCodecs object, for example, if you have a RasterCodecs object called rasterCodecsInstance, then you can access the CodecsRasterizeDocumentLoadOptions.XResolution using:

rasterCodecsInstance.RasterizeDocument.Load.XResolution

And hence, the FullPropertyName if this option will be RasterizeDocument.Load.XResolution.

The LoadOptions(string fileName) and LoadOptions(Stream stream) methods will merge the content of the XML file with the current RasterCodecs options. Therefore, you can delete any option elements that do not override the default behavior from the file if desired.

Example

This example shows how to save the options and then load them in a server application.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
 
// A bare-boned REST service that loads an image from a URL and returns it as PNG 
[System.ServiceModel.ServiceContract()] 
public interface ISampleService 
{ 
   [System.ServiceModel.OperationContract(Name = "Load", IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "Load")] 
   [System.ServiceModel.Web.WebGet(UriTemplate = "/load?url={url}&page={pageNumber}")] 
   System.IO.Stream Load(string url, int pageNumber); 
} 
 
// Implementation 
public class SampleService : ISampleService 
{ 
   // This is the REST service call 
   public System.IO.Stream Load(string url, int pageNumber) 
   { 
      // Load the page 
      using (RasterCodecs rasterCodecs = new RasterCodecs()) 
      { 
         // Get the name of the options file from the configuraion file 
         string optionsFilePath = System.Configuration.ConfigurationManager.AppSettings["RasterCodecsOptionsFilePath"]; 
 
         // See if it is set and contains a valid file 
         if (optionsFilePath != null && System.IO.File.Exists(optionsFilePath)) 
         { 
            // Set it, this will use the options previously saved with SampleService.PrepareOptions 
            rasterCodecs.LoadOptions(optionsFilePath); 
         } 
 
         // Now load the image 
         using (RasterImage rasterImage = rasterCodecs.Load(new Uri(url), pageNumber)) 
         { 
            // Save it as PNG 
            System.IO.MemoryStream ms = new System.IO.MemoryStream(); 
            rasterCodecs.Save(rasterImage, ms, RasterImageFormat.Png, 24); 
 
            // Set the content length and MIME type 
            System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "image/png"; 
            System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentLength = ms.Length; 
 
            ms.Position = 0; 
            return ms; 
         } 
      } 
   } 
 
   // This is a helper method to create the RasterCodecs options file. This method 
   // is meant to be called from ourside the service by an administrator. 
   // 
   // We can change any option we want off-line and then save the file 
   // Our service will pick up the new options from the file and use them 
   public static void PrepareOptions() 
   { 
      // Get the name of the options file from the configuraion file 
      string optionsFilePath = System.Configuration.ConfigurationManager.AppSettings["RasterCodecsOptionsFilePath"]; 
 
      // See if it is set 
      if (optionsFilePath != null) 
      { 
         // Yes, create a new RasterCodecs object 
         using (RasterCodecs rasterCodecs = new RasterCodecs()) 
         { 
            // Change any options, for example, set the default resolution for document files ... 
            rasterCodecs.Options.RasterizeDocument.Load.XResolution = 300; 
            rasterCodecs.Options.RasterizeDocument.Load.YResolution = 300; 
            // And enable loading text files as RasterImage support 
            rasterCodecs.Options.Txt.Load.Enabled = true; 
 
            // Save the options to the file specified by the config 
            rasterCodecs.SaveOptions(optionsFilePath); 
         } 
      } 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
' A bare-boned REST service that loads an image from a URL and returns it as PNG 
<System.ServiceModel.ServiceContract()> 
Public Interface ISampleService 
   <System.ServiceModel.OperationContract(Name:="Load", IsTerminating:=False, IsInitiating:=True, IsOneWay:=False, AsyncPattern:=False, Action:="Load")> 
   <System.ServiceModel.Web.WebGet(UriTemplate:="/load?url={url}&page={pageNumber}")> 
   Function Load(url As String, pageNumber As Integer) As System.IO.Stream 
End Interface 
 
' Implementation 
Public Class SampleService 
   Implements ISampleService 
 
   ' This is the REST service call 
   Public Function Load(url As String, pageNumber As Integer) As System.IO.Stream Implements ISampleService.Load 
      ' Load the page 
      Using rasterCodecs As New RasterCodecs() 
         ' Get the name of the options file from the configuraion file 
         Dim optionsFilePath As String = System.Configuration.ConfigurationManager.AppSettings("RasterCodecsOptionsFilePath") 
 
         ' See if it is set and contains a valid file 
         If Not IsNothing(optionsFilePath) AndAlso System.IO.File.Exists(optionsFilePath) Then 
            ' Set it, this will use the options previously saved with SampleService.PrepareOptions 
            rasterCodecs.LoadOptions(optionsFilePath) 
         End If 
 
         ' Now load the image 
         Using rasterImage As RasterImage = rasterCodecs.Load(New Uri(url), pageNumber) 
            ' Save it as PNG 
            Dim ms As New System.IO.MemoryStream() 
            rasterCodecs.Save(rasterImage, ms, RasterImageFormat.Png, 24) 
 
            ' Set the content length and MIME type 
            System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "image/png" 
            System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentLength = ms.Length 
 
            ms.Position = 0 
            Return ms 
         End Using 
      End Using 
   End Function 
 
   ' This is a helper method to create the RasterCodecs options file. This method 
   ' is meant to be called from ourside the service by an administrator. 
   ' 
   ' We can change any option we want off-line and then save the file 
   ' Our service will pick up the new options from the file and use them 
   Public Shared Sub PrepareOptions() 
      ' Get the name of the options file from the configuraion file 
      Dim optionsFilePath As String = System.Configuration.ConfigurationManager.AppSettings("RasterCodecsOptionsFilePath") 
 
      ' See if it is set 
      If Not IsNothing(optionsFilePath) Then 
         ' Yes, create a new RasterCodecs object 
         Using rasterCodecs As New RasterCodecs() 
            ' Change any options, for example, set the default resolution for document files ... 
            rasterCodecs.Options.RasterizeDocument.Load.XResolution = 300 
            rasterCodecs.Options.RasterizeDocument.Load.YResolution = 300 
            ' And enable loading text files as RasterImage support 
            rasterCodecs.Options.Txt.Load.Enabled = True 
 
            ' Save the options to the file specified by the config 
            rasterCodecs.SaveOptions(optionsFilePath) 
         End Using 
      End If 
   End Sub 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly