Class PngOptions

Class PngOptions

Namespace: Aspose.Imaging.ImageOptions
Assembly: Aspose.Imaging.dll (25.7.0)

Create high-quality Portable Network Graphics (PNG) raster images effortlesslywith our API, offering customizable options for compression levels,bits per pixel depths, and alpha bits. Seamlessly process XMP metadata containers,ensuring comprehensive image metadata management, and empowering you to tailorPNG images to your exact specifications with ease.

public class PngOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
    {
    }
The above code is already formatted according to standard C# conventions. No further reformatting is necessary.

Inheritance

object DisposableObject ImageOptionsBase PngOptions

Derived

ApngOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

Inherited Members

ImageOptionsBase.Clone() , ImageOptionsBase.ReleaseManagedResources() , ImageOptionsBase.KeepMetadata , ImageOptionsBase.XmpData , ImageOptionsBase.Source , ImageOptionsBase.Palette , ImageOptionsBase.ResolutionSettings , ImageOptionsBase.VectorRasterizationOptions , ImageOptionsBase.BufferSizeHint , ImageOptionsBase.MultiPageOptions , ImageOptionsBase.FullFrame , ImageOptionsBase.ProgressEventHandler , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

This example demonstrates the use of different classes from SaveOptions Namespace for export purposes. An image of type Gif is loaded into an instance of Image and then exported out to several formats.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
   {
       image.Save(dir + "output.bmp", new Aspose.Imaging.ImageOptions.BmpOptions());
       image.Save(dir + "output.jpg", new Aspose.Imaging.ImageOptions.JpegOptions());
       image.Save(dir + "output.png", new Aspose.Imaging.ImageOptions.PngOptions());
       image.Save(dir + "output.tif", new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default));
   }

The following example shows how to convert a multipage vector image to PNG format in general way without referencing to a particular image type.

string dir = "C:\\aspose.imaging\\net\\misc\\ImagingReleaseQATester\\Tests\\testdata\\2548";
   string inputFilePath = System.IO.Path.Combine(dir, "Multipage.cdr");
   string outputFilePath = System.IO.Path.Combine(dir, "Multipage.cdr.png");
   Aspose.Imaging.ImageOptionsBase exportOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFilePath))
   {
      exportOptions.MultiPageOptions = null;
      Aspose.Imaging.IMultipageImage multipageImage = image as Aspose.Imaging.IMultipageImage;
      if (multipageImage != null && (multipageImage.Pages != null && multipageImage.PageCount > 2))
      {
         exportOptions.MultiPageOptions = new Aspose.Imaging.ImageOptions.MultiPageOptions(new Aspose.Imaging.IntRange(0, 2));
      }
      if (image is Aspose.Imaging.VectorImage)
      {
         exportOptions.VectorRasterizationOptions = (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
         exportOptions.VectorRasterizationOptions.TextRenderingHint = Aspose.Imaging.TextRenderingHint.SingleBitPerPixel;
         exportOptions.VectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
      }
      image.Save(outputFilePath, exportOptions);
   }

This example uses Graphics class to create primitive shapes on the Image surface. To demonstrate the operation, the example creates a new Image in PNG format and draw primitive shapes on Image surface using Draw methods exposed by Graphics class

using System.IO;
   using Aspose.Imaging;
   using Aspose.Imaging.Brushes;
   using Aspose.Imaging.Sources;
   using Aspose.Imaging.Fonts;
   using (FileStream stream = new FileStream(@"C:\temp\output.png", FileMode.Create))
   {
       var pngOptions = new PngOptions();
       pngOptions.Source = new StreamSource(stream);
       using (Image image = Image.Create(pngOptions, 500, 500))
       {
           var graphics = new Graphics(image);
           graphics.Clear(Color.Wheat);
           graphics.DrawArc(new Pen(Color.Black, 2), new Rectangle(200, 200, 100, 200), 0, 300);
           graphics.DrawBezier(new Pen(Color.Blue, 2), new Point(250, 100), new Point(300, 30), new Point(450, 100), new Point(235, 25));
           graphics.DrawCurve(new Pen(Color.Green, 2), new[] { new Point(100, 200), new Point(100, 350), new Point(200, 450) });
           graphics.DrawEllipse(new Pen(Color.Yellow, 2), new Rectangle(300, 300, 100, 100));
           graphics.DrawLine(new Pen(Color.Violet, 2), new Point(100, 100), new Point(200, 200));
           graphics.DrawPie(new Pen(Color.Silver, 2), new Rectangle(new Point(200, 20), new Size(200, 200)), 0, 45);
           graphics.DrawPolygon(new Pen(Color.Red, 2), new[] { new Point(20, 100), new Point(20, 200), new Point(220, 20) });
           graphics.DrawRectangle(new Pen(Color.Orange, 2), new Rectangle(new Point(250, 250), new Size(100, 100)));
           var brush = new SolidBrush();
           brush.Color = Color.Purple;
           brush.Opacity = 100;
           graphics.DrawString("This image is created by Aspose.Imaging API", new Font("Times New Roman", 16), brush, new PointF(50, 400));
           image.Save();
       }
   }

Constructors

PngOptions()

Initializes a new instance of the Aspose.Imaging.ImageOptions.PngOptions class.

public PngOptions()
   {
   }

PngOptions(PngOptions)

Initializes a new instance of the Aspose.Imaging.ImageOptions.PngOptions class.

public PngOptions(PngOptions pngOptions)
   {
   }

Parameters

pngOptions PngOptions

The PNG options.

Fields

DefaultCompressionLevel

The default compression level.

public const PngCompressionLevel DefaultCompressionLevel = DeflateRecommended;

Field Value

PngCompressionLevel

Properties

BitDepth

Gets or sets the bit depth values in range of 1, 2, 4, 8, 16.

Mind the next limits:

Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor supports bit depth of 1, 2, 4, 8.

Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale, Aspose.Imaging.FileFormats.Png.PngColorType.GrayscaleWithAlpha support bit depth of 8.

Aspose.Imaging.FileFormats.Png.PngColorType.Truecolor, Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha support bit depth of 8, 16.

public byte BitDepth
   {
      get;
      set;
   }

Property Value

byte

Examples

This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.BitDepth = 8;
   createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   createOptions.CompressionLevel = 9;
   createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;
   createOptions.Progressive = true;
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       pngImage.Save(dir + "output.explicitoptions.png");
   }

The following example shows how to save an image to PNG format using various options.

string dir = "c:\\temp\\";
   using (var pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
   {
       var gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       var graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       var saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       saveOptions.Progressive = true;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       saveOptions.CompressionLevel = 9;
       saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;
       saveOptions.BitDepth = 8;
       pngImage.Save(dir + "output.png", saveOptions);
   }

ColorType

Gets or sets the type of the color.

public PngColorType ColorType
   {
      get;
      set;
   }

Property Value

PngColorType

Examples

The following example shows how to compress a PNG image, using indexed color with best fit palette

string sourceFilePath = "OriginalRings.png";
   string outputFilePath = "OriginalRingsOutput.png";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath))
   {
       image.Save(outputFilePath, new Aspose.Imaging.ImageOptions.PngOptions()
       {
           Progressive = true,
           ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
           CompressionLevel = 9,
           Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
       });
   }

This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.BitDepth = 8;
   createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   createOptions.CompressionLevel = 9;
   createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;
   createOptions.Progressive = true;
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
   {
      Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
            new Aspose.Imaging.Point(0, 0),
            new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
            Aspose.Imaging.Color.Blue,
            Aspose.Imaging.Color.Transparent);
      Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
      graphics.FillRectangle(gradientBrush, pngImage.Bounds);
      pngImage.Save(dir + "output.explicitoptions.png");
   }

The following example shows how to save an image to PNG format using various options.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       saveOptions.Progressive = true;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       saveOptions.CompressionLevel = 9;
       saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;
       saveOptions.BitDepth = 8;
       pngImage.Save(dir + "output.png", saveOptions);
   }

CompressionLevel

Gets or sets the Aspose.Imaging.FileFormats.Png.PngImage compression level.

using System;
[Obsolete("This property is obsolete. Use PngCompressionLevel instead.", false)]
public int CompressionLevel
{
    get;
    set;
}

Property Value

int

Examples

The following example shows how to compress a PNG image, using indexed color with best fit palette

string sourceFilePath = "OriginalRings.png";
   string outputFilePath = "OriginalRingsOutput.png";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath))
   {
       image.Save(outputFilePath, new Aspose.Imaging.ImageOptions.PngOptions()
       {
           Progressive = true,
           ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
           CompressionLevel = 9,
           Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
       });
   }

This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.BitDepth = 8;
   createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   createOptions.CompressionLevel = 9;
   createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;
   createOptions.Progressive = true;
   using (var pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
   {
      Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
            new Aspose.Imaging.Point(0, 0),
            new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
            Aspose.Imaging.Color.Blue,
            Aspose.Imaging.Color.Transparent);
      Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
      graphics.FillRectangle(gradientBrush, pngImage.Bounds);
      pngImage.Save(dir + "output.explicitoptions.png");
   }

The following example shows how to save an image to PNG format using various options.

string dir = "c:\\temp\\";
   using (var pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
   {
       var gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       var graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       var saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       saveOptions.Progressive = true;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       saveOptions.CompressionLevel = 9;
       saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;
       saveOptions.BitDepth = 8;
       pngImage.Save(dir + "output.png", saveOptions);
   }

FilterType

Gets or sets the filter type used during png file save process.

public PngFilterType FilterType
   {
      get;
      set;
   }

Property Value

PngFilterType

Examples

This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.BitDepth = 8;
   createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   createOptions.CompressionLevel = 9;
   createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;
   createOptions.Progressive = true;
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       pngImage.Save(dir + "output.explicitoptions.png");
   }

The following example shows how different filter types affect the size of the output PNG image.

Aspose.Imaging.FileFormats.Png.PngFilterType[] filterTypes = new Aspose.Imaging.FileFormats.Png.PngFilterType[]
   {
       Aspose.Imaging.FileFormats.Png.PngFilterType.None,
       Aspose.Imaging.FileFormats.Png.PngFilterType.Up,
       Aspose.Imaging.FileFormats.Png.PngFilterType.Sub,
       Aspose.Imaging.FileFormats.Png.PngFilterType.Paeth,
       Aspose.Imaging.FileFormats.Png.PngFilterType.Avg,
       Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive,
   };
   foreach (Aspose.Imaging.FileFormats.Png.PngFilterType filterType in filterTypes)
   {
       Aspose.Imaging.ImageOptions.PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
       using (Aspose.Imaging.Image image = Image.Load("c:\\temp\\sample.png"))
       {
           options.FilterType = filterType;
           using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
           {
               image.Save(stream, options);
               System.Console.WriteLine("The filter type is {0}, the output image size is {1} bytes.", filterType, stream.Length);
           }
       }
   }
This code has been properly indented, spaced, and formatted for general readability improvements according to C# conventions. No other changes have been made.

The following example shows how to save an image to PNG format using various options.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       saveOptions.Progressive = true;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       saveOptions.CompressionLevel = 9;
       saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;
       saveOptions.BitDepth = 8;
       pngImage.Save(dir + "output.png", saveOptions);
   }

PngCompressionLevel

Gets or sets the Aspose.Imaging.FileFormats.Png.PngImage compression level.

public PngCompressionLevel PngCompressionLevel
   {
      get;
      set;
   }

Property Value

PngCompressionLevel

Progressive

Gets or sets a value indicating whether a Aspose.Imaging.FileFormats.Png.PngImage is progressive.

public bool Progressive
    {
        get;
        set;
    }

Property Value

bool

Examples

The following example shows how to compress a PNG image, using indexed color with best fit palette

string sourceFilePath = "OriginalRings.png";
   string outputFilePath = "OriginalRingsOutput.png";
   using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath))
   {
       image.Save(outputFilePath, new Aspose.Imaging.ImageOptions.PngOptions()
       {
           Progressive = true,
           ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
           CompressionLevel = 9,
           Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
       });
   }

This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.

string dir = "c:\\temp\\";
   Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
   createOptions.BitDepth = 8;
   createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
   createOptions.CompressionLevel = 9;
   createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;
   createOptions.Progressive = true;
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(createOptions, 100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       pngImage.Save(dir + "output.explicitoptions.png");
   }

The following example shows how to save an image to PNG format using various options.

string dir = "c:\\temp\\";
   using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(100, 100))
   {
       Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
           new Aspose.Imaging.Point(0, 0),
           new Aspose.Imaging.Point(pngImage.Width, pngImage.Height),
           Aspose.Imaging.Color.Blue,
           Aspose.Imaging.Color.Transparent);
       Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(pngImage);
       graphics.FillRectangle(gradientBrush, pngImage.Bounds);
       Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
       saveOptions.Progressive = true;
       saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);
       saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
       saveOptions.CompressionLevel = 9;
       saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;
       saveOptions.BitDepth = 8;
       pngImage.Save(dir + "output.png", saveOptions);
   }
 English