SaveOptions(Stream) Method (original) (raw)

Syntax

public void SaveOptions( Stream _stream_ )

public: void SaveOptions( Stream^ _stream_ )

Parameters

stream
A Stream that will contain the output data.

Example

using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using 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}")] 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 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); } } } }

Leadtools.Codecs Assembly

CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

StartCompress(int,int,int,RasterByteOrder,RasterViewPerspective,int,byte[],int,int,CodecsCompression,CodecsCompressDataCallback) Method