LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

CodecsPngOptions Class

Example 





Members 
Provides extra options for loading and saving PNG images. .NET support WinRT support Silverlight support
Object Model
CodecsPngOptions ClassCodecsPngLoadOptions ClassCodecsPngSaveOptions Class
Syntax
public class CodecsPngOptions 
'Declaration
 
Public Class CodecsPngOptions 
'Usage
 
Dim instance As CodecsPngOptions
public sealed class CodecsPngOptions 
function Leadtools.Codecs.CodecsPngOptions()
public ref class CodecsPngOptions 
Example
 
Public Sub CodecsPngOptionsExample()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
      Dim image As RasterImage = codecs.Load(srcFileName)

      ' save with maximum quality
      codecs.Options.Png.Save.QualityFactor = 1
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "quality.png"), RasterImageFormat.Png, image.BitsPerPixel)

      ' save with maximum compression
      codecs.Options.Png.Save.QualityFactor = 9
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "compression.png"), RasterImageFormat.Png, image.BitsPerPixel)

      ' Clean up
      image.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void CodecsPngOptionsExample()
     {
         RasterCodecs codecs = new RasterCodecs();

         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
         RasterImage image = codecs.Load(srcFileName);

         // save with maximum quality
         codecs.Options.Png.Save.QualityFactor = 1;
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "quality.png"), RasterImageFormat.Png, image.BitsPerPixel);

         // save with maximum compression
         codecs.Options.Png.Save.QualityFactor = 9;
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "compression.png"), RasterImageFormat.Png, image.BitsPerPixel);

         // Clean up
         image.Dispose();
         codecs.Dispose();
     }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsPngOptionsExample = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var image;
         // Load the image
         var srcFileName = "Assets\\Image1.cmp";
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) {
            image = img;

            //Save as PNG
            // save with maximum quality
            codecs.options.png.save.qualityFactor = 1;

            var destFileName = "quality.png";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.png, image.bitsPerPixel)
         })
         .then(function () {

            // save with maximum compression
            codecs.options.png.save.qualityFactor = 9;
            destFileName = "compression.png";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.png, image.bitsPerPixel)
         })
         .then(function () {
            // Clean up
            image.close();
            codecs.close();
         })
      }
   }
}
[TestMethod]
public async Task CodecsPngOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load the image
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   //Save as PNG
   // save with maximum quality
   codecs.Options.Png.Save.QualityFactor = 1;
   string destFileName = @"quality.png";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Png, image.BitsPerPixel);

   // save with maximum compression
   codecs.Options.Png.Save.QualityFactor = 9;
   destFileName = @"compression.png";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Png, image.BitsPerPixel);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
public void CodecsPngOptionsExample(Stream inStream, Stream outStreamPng1, Stream outStreamPng2)
{
   RasterCodecs codecs = new RasterCodecs();
   RasterImage image = codecs.Load(inStream);

   // save with maximum quality
   codecs.Options.Png.Save.QualityFactor = 1;
   codecs.Save(image, outStreamPng1, RasterImageFormat.Png, image.BitsPerPixel);

   // save with maximum compression
   codecs.Options.Png.Save.QualityFactor = 9;
   codecs.Save(image, outStreamPng2, RasterImageFormat.Png, image.BitsPerPixel);

   // Clean up
   image.Dispose();
}
Public Sub CodecsPngOptionsExample(ByVal inStream As Stream, ByVal outStreamPng1 As Stream, ByVal outStreamPng2 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim image As RasterImage = codecs.Load(inStream)

   ' save with maximum quality
   codecs.Options.Png.Save.QualityFactor = 1
   codecs.Save(image, outStreamPng1, RasterImageFormat.Png, image.BitsPerPixel)

   ' save with maximum compression
   codecs.Options.Png.Save.QualityFactor = 9
   codecs.Save(image, outStreamPng2, RasterImageFormat.Png, image.BitsPerPixel)

   ' Clean up
   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CodecsPngOptions Members
Leadtools.Codecs Namespace
PNG Files and Transparency

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.