Class PngOptions

Class PngOptions

De naam: Aspose.Imaging.ImageOptions Verzameling: Aspose.Imaging.dll (25.4.0)

Creëren van hoge kwaliteit Portable Network Graphics (PNG) raster afbeeldingen zonder moeitemet onze API, met aangepaste opties voor compressie niveaus,bits per pixel diepte, en alfa bit. onlosmakelijk verwerken XMP metadata containers,Om een uitgebreid beeldmetadata-beheer te garanderen en u in staat te stellen zich aan te passenPNG afbeeldingen naar uw exacte specificaties met gemakkelijkheid.

public class PngOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable

Inheritance

object DisposableObject ImageOptionsBase PngOptions

Derived

ApngOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

Geëerbiede leden

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

Dit voorbeeld toont het gebruik van verschillende klassen van SaveOptions Namespace voor exportdoeleinden.Een Gif-beeld wordt in een beeldinstantie geladen en vervolgens naar meerdere formaten uitgevoerd.

string dir = "c:\\temp\\";

                                                                                                                                                                                                                    //Load an existing image (of type Gif) in an instance of Image class
                                                                                                                                                                                                                    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.gif"))
                                                                                                                                                                                                                    {
                                                                                                                                                                                                                        //Export to BMP file format using the default options
                                                                                                                                                                                                                        image.Save(dir + "output.bmp", new Aspose.Imaging.ImageOptions.BmpOptions());

                                                                                                                                                                                                                        //Export to JPEG file format using the default options
                                                                                                                                                                                                                        image.Save(dir + "output.jpg", new Aspose.Imaging.ImageOptions.JpegOptions());

                                                                                                                                                                                                                        //Export to PNG file format using the default options
                                                                                                                                                                                                                        image.Save(dir + "output.png", new Aspose.Imaging.ImageOptions.PngOptions());

                                                                                                                                                                                                                        //Export to TIFF file format using the default options
                                                                                                                                                                                                                        image.Save(dir + "output.tif", new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default));
                                                                                                                                                                                                                    }

Het volgende voorbeeld toont hoe je een multipage vector-afbeelding in het PNG-formaat over het algemeen kunt converteren zonder verwijzing naar een specifiek beeldtype.

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;

                                                                                                                                                               // Export only first two pages. In fact, only one page will be rasterized because PNG is not a multi-page format.
                                                                                                                                                               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);
                                                                                                                                                           }

Dit voorbeeld gebruikt de Graphics-klasse om primitieve vormen op het beeldoppervlak te creëren. om de werking te demonstreren, creëert het model een nieuw beeld in PNG-formaat en draagt primitief vormes op de beeldovergrond met behulp van Draw methoden die worden blootgesteld door de grafische klasse.

//Creates an instance of FileStream
                                                                                                                                                                                                                                                                using (System.IO.FileStream stream = new System.IO.FileStream(@"C:\temp\output.png", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                                {
                                                                                                                                                                                                                                                                    //Create an instance of PngOptions and set its various properties
                                                                                                                                                                                                                                                                    Aspose.Imaging.ImageOptions.PngOptions pngOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                                                                                                                                    //Set the Source for PngOptions
                                                                                                                                                                                                                                                                    pngOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

                                                                                                                                                                                                                                                                    //Create an instance of Image 
                                                                                                                                                                                                                                                                    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(pngOptions, 500, 500))
                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                        //Create and initialize an instance of Graphics class
                                                                                                                                                                                                                                                                        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);

                                                                                                                                                                                                                                                                        //Clear Graphics surface
                                                                                                                                                                                                                                                                        graphics.Clear(Aspose.Imaging.Color.Wheat);

                                                                                                                                                                                                                                                                        //Draw an Arc by specifying the Pen object having Black color, 
                                                                                                                                                                                                                                                                        //a Rectangle surrounding the Arc, Start Angle and Sweep Angle
                                                                                                                                                                                                                                                                        graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 2), new Aspose.Imaging.Rectangle(200, 200, 100, 200), 0, 300);

                                                                                                                                                                                                                                                                        //Draw a Bezier by specifying the Pen object having Blue color and co-ordinate Points.
                                                                                                                                                                                                                                                                        graphics.DrawBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Point(250, 100), new Aspose.Imaging.Point(300, 30), new Aspose.Imaging.Point(450, 100), new Aspose.Imaging.Point(235, 25));

                                                                                                                                                                                                                                                                        //Draw a Curve by specifying the Pen object having Green color and an array of Points
                                                                                                                                                                                                                                                                        graphics.DrawCurve(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new[] { new Aspose.Imaging.Point(100, 200), new Aspose.Imaging.Point(100, 350), new Aspose.Imaging.Point(200, 450) });

                                                                                                                                                                                                                                                                        //Draw an Ellipse using the Pen object and a surrounding Rectangle
                                                                                                                                                                                                                                                                        graphics.DrawEllipse(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Yellow, 2), new Aspose.Imaging.Rectangle(300, 300, 100, 100));

                                                                                                                                                                                                                                                                        //Draw a Line 
                                                                                                                                                                                                                                                                        graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Violet, 2), new Aspose.Imaging.Point(100, 100), new Aspose.Imaging.Point(200, 200));

                                                                                                                                                                                                                                                                        //Draw a Pie segment
                                                                                                                                                                                                                                                                        graphics.DrawPie(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Silver, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(200, 20), new Aspose.Imaging.Size(200, 200)), 0, 45);

                                                                                                                                                                                                                                                                        //Draw a Polygon by specifying the Pen object having Red color and an array of Points
                                                                                                                                                                                                                                                                        graphics.DrawPolygon(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2), new[] { new Aspose.Imaging.Point(20, 100), new Aspose.Imaging.Point(20, 200), new Aspose.Imaging.Point(220, 20) });

                                                                                                                                                                                                                                                                        //Draw a Rectangle
                                                                                                                                                                                                                                                                        graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 2), new Aspose.Imaging.Rectangle(new Aspose.Imaging.Point(250, 250), new Aspose.Imaging.Size(100, 100)));

                                                                                                                                                                                                                                                                        //Create a SolidBrush object and set its various properties
                                                                                                                                                                                                                                                                        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
                                                                                                                                                                                                                                                                        brush.Color = Color.Purple;
                                                                                                                                                                                                                                                                        brush.Opacity = 100;

                                                                                                                                                                                                                                                                        //Draw a String using the SolidBrush object and Font, at specific Point
                                                                                                                                                                                                                                                                        graphics.DrawString("This image is created by Aspose.Imaging API", new Aspose.Imaging.Font("Times New Roman", 16), brush, new Aspose.Imaging.PointF(50, 400));

                                                                                                                                                                                                                                                                        // save all changes.
                                                                                                                                                                                                                                                                        image.Save();
                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                }

Constructors

PngOptions()

Initialiseert een nieuwe instantie van de Aspose.Imaging.ImageOptions.Pngoptions klasse.

public PngOptions()

PngOptions(PngOptions)

Initialiseert een nieuwe instantie van de Aspose.Imaging.ImageOptions.Pngoptions klasse.

public PngOptions(PngOptions pngOptions)

Parameters

pngOptions PngOptions

De PNG opties.

Fields

DefaultCompressionLevel

De standaard compressie niveau.

public const int DefaultCompressionLevel = 6

veldwaarde

int

Properties

BitDepth

Geeft of stelt de bit diepte waarden in het bereik van 1, 2, 4, 8, 16.

Denk aan de volgende grenzen:

Aspose.Imaging.FileFormats.Png.Type.IndexedColor ondersteunt een bit diepte van 1, 2, 4, 8.

Aspose.Imaging.FileFormats.Png.pngColorType.Grayscale, Wl17.Diplomaatformaten. png-pnngColortyp.grasscalenWithAlpha ondersteunt bit diepte van 8.

Aspose.Imaging.FileFormats.Png.pngColorType.Truecolor, _wl17.fileFormates.ping. pngcolortypes.trucolorsWithAlpha ondersteunt bit diepte van 8, 16.

public byte BitDepth { get; set; }

Eigendomswaarde

byte

Examples

Dit voorbeeld laat zien hoe je een PNG-afbeelding kunt maken met de aangegeven opties, het kunt vullen met een lineaire gradient kleur en het in een bestand kunt opslaan.

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                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);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Het volgende voorbeeld toont hoe je een afbeelding in PNG-formaat kunt opslaan met behulp van verschillende opties.

string dir = "c:\\temp\\";

                                                                                                // Create a PNG image of 100x100 px.
                                                                                                // You can also load image of any supported format from a file or a stream.
                                                                                                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);

                                                                                                    // Fill the image with the blue-transparent gradient.
                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                    // Progressive loading.
                                                                                                    saveOptions.Progressive = true;

                                                                                                    // Set the horizontal and vertical resolution to 96 pixels per inch.
                                                                                                    saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);

                                                                                                    // Each pixel is a (red, green, blue) triple followed by alpha.
                                                                                                    saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                    // Set the maximum level of compression.
                                                                                                    saveOptions.CompressionLevel = 9;

                                                                                                    // This is the best compression, but the slowest execution time.
                                                                                                    // Adaptive filtering means that saving process will choose most sutable filter for each data row.
                                                                                                    saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;

                                                                                                    // The number of bits per channel.
                                                                                                    saveOptions.BitDepth = 8;

                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "output.png", saveOptions);
                                                                                                }

ColorType

Geeft of bepaalt het type kleur.

public PngColorType ColorType { get; set; }

Eigendomswaarde

PngColorType

Examples

Het volgende voorbeeld laat zien hoe je een PNG-afbeelding kunt compresseren, met behulp van geïndexeerde kleur met de best fit palet.

// Loads png image        
                                                                                                                 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,
                                                                                                                          // Use indexed color type
                                                                                                                      ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
                                                                                                                          // Use maximal compression
                                                                                                                      CompressionLevel = 9,
                                                                                                                   // Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
                                                                                                                      // is almost visually indistinguishable from a non-palletized one.
                                                                                                                      Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
                                                                                                                 });
                                                                                                             }
                                                                                                                 // The output file size should be significantly reduced

Dit voorbeeld laat zien hoe je een PNG-afbeelding kunt maken met de aangegeven opties, het kunt vullen met een lineaire gradient kleur en het in een bestand kunt opslaan.

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                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);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Het volgende voorbeeld toont hoe je een afbeelding in PNG-formaat kunt opslaan met behulp van verschillende opties.

string dir = "c:\\temp\\";

                                                                                                // Create a PNG image of 100x100 px.
                                                                                                // You can also load image of any supported format from a file or a stream.
                                                                                                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);

                                                                                                    // Fill the image with the blue-transparent gradient.
                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                    // Progressive loading.
                                                                                                    saveOptions.Progressive = true;

                                                                                                    // Set the horizontal and vertical resolution to 96 pixels per inch.
                                                                                                    saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);

                                                                                                    // Each pixel is a (red, green, blue) triple followed by alpha.
                                                                                                    saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                    // Set the maximum level of compression.
                                                                                                    saveOptions.CompressionLevel = 9;

                                                                                                    // This is the best compression, but the slowest execution time.
                                                                                                    // Adaptive filtering means that saving process will choose most sutable filter for each data row.
                                                                                                    saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;

                                                                                                    // The number of bits per channel.
                                                                                                    saveOptions.BitDepth = 8;

                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "output.png", saveOptions);
                                                                                                }

CompressionLevel

Geeft of stelt het Aspose.Imaging.FileFormats.Png.pngImage compressie niveau in het bereik van 0-9. hoe hoger de waarde - hoe efficiënter de compression.

public int CompressionLevel { get; set; }

Eigendomswaarde

int

Examples

Het volgende voorbeeld laat zien hoe je een PNG-afbeelding kunt compresseren, met behulp van geïndexeerde kleur met de best fit palet.

// Loads png image        
                                                                                                                 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,
                                                                                                                          // Use indexed color type
                                                                                                                      ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
                                                                                                                          // Use maximal compression
                                                                                                                      CompressionLevel = 9,
                                                                                                                   // Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
                                                                                                                      // is almost visually indistinguishable from a non-palletized one.
                                                                                                                      Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
                                                                                                                 });
                                                                                                             }
                                                                                                                 // The output file size should be significantly reduced

Dit voorbeeld laat zien hoe je een PNG-afbeelding kunt maken met de aangegeven opties, het kunt vullen met een lineaire gradient kleur en het in een bestand kunt opslaan.

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                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);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Het volgende voorbeeld toont hoe je een afbeelding in PNG-formaat kunt opslaan met behulp van verschillende opties.

string dir = "c:\\temp\\";

                                                                                                // Create a PNG image of 100x100 px.
                                                                                                // You can also load image of any supported format from a file or a stream.
                                                                                                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);

                                                                                                    // Fill the image with the blue-transparent gradient.
                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                    // Progressive loading.
                                                                                                    saveOptions.Progressive = true;

                                                                                                    // Set the horizontal and vertical resolution to 96 pixels per inch.
                                                                                                    saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);

                                                                                                    // Each pixel is a (red, green, blue) triple followed by alpha.
                                                                                                    saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                    // Set the maximum level of compression.
                                                                                                    saveOptions.CompressionLevel = 9;

                                                                                                    // This is the best compression, but the slowest execution time.
                                                                                                    // Adaptive filtering means that saving process will choose most sutable filter for each data row.
                                                                                                    saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;

                                                                                                    // The number of bits per channel.
                                                                                                    saveOptions.BitDepth = 8;

                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "output.png", saveOptions);
                                                                                                }

FilterType

Geeft of stelt het filter type gebruikt tijdens het png-bestand opslaan proces.

public PngFilterType FilterType { get; set; }

Eigendomswaarde

PngFilterType

Examples

Dit voorbeeld laat zien hoe je een PNG-afbeelding kunt maken met de aangegeven opties, het kunt vullen met een lineaire gradient kleur en het in een bestand kunt opslaan.

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                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);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Het volgende voorbeeld toont hoe verschillende filters de grootte van de PNG-afbeelding beïnvloeden.

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"))
                                                                                                              {
                                                                                                                  // Set a filter type
                                                                                                                  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);
                                                                                                                  }
                                                                                                              }
                                                                                                          }

                                                                                                          //The output may look like this:
                                                                                                          //The filter type is None, the output image size is 116845 bytes.
                                                                                                          //The filter type is Up, the output image size is 86360 bytes.
                                                                                                          //The filter type is Sub, the output image size is 94907 bytes.
                                                                                                          //The filter type is Paeth, the output image size is 86403 bytes.
                                                                                                          //The filter type is Avg, the output image size is 89956 bytes.
                                                                                                          //The filter type is Adaptive, the output image size is 97248 bytes.

Het volgende voorbeeld toont hoe je een afbeelding in PNG-formaat kunt opslaan met behulp van verschillende opties.

string dir = "c:\\temp\\";

                                                                                                // Create a PNG image of 100x100 px.
                                                                                                // You can also load image of any supported format from a file or a stream.
                                                                                                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);

                                                                                                    // Fill the image with the blue-transparent gradient.
                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                    // Progressive loading.
                                                                                                    saveOptions.Progressive = true;

                                                                                                    // Set the horizontal and vertical resolution to 96 pixels per inch.
                                                                                                    saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);

                                                                                                    // Each pixel is a (red, green, blue) triple followed by alpha.
                                                                                                    saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                    // Set the maximum level of compression.
                                                                                                    saveOptions.CompressionLevel = 9;

                                                                                                    // This is the best compression, but the slowest execution time.
                                                                                                    // Adaptive filtering means that saving process will choose most sutable filter for each data row.
                                                                                                    saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;

                                                                                                    // The number of bits per channel.
                                                                                                    saveOptions.BitDepth = 8;

                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "output.png", saveOptions);
                                                                                                }

Progressive

Geeft of stelt een waarde aan die aanwijst of een Aspose.Imaging.FileFormats.Png. PngImage progressief is.

public bool Progressive { get; set; }

Eigendomswaarde

bool

Examples

Het volgende voorbeeld laat zien hoe je een PNG-afbeelding kunt compresseren, met behulp van geïndexeerde kleur met de best fit palet.

// Loads png image        
                                                                                                                 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,
                                                                                                                          // Use indexed color type
                                                                                                                      ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.IndexedColor,
                                                                                                                          // Use maximal compression
                                                                                                                      CompressionLevel = 9,
                                                                                                                   // Get the closest 8-bit color palette which covers as many pixels as possible, so that a palettized image
                                                                                                                      // is almost visually indistinguishable from a non-palletized one.
                                                                                                                      Palette = Aspose.Imaging.ColorPaletteHelper.GetCloseImagePalette((Aspose.Imaging.RasterImage)image, 256, Aspose.Imaging.PaletteMiningMethod.Histogram)
                                                                                                                 });
                                                                                                             }
                                                                                                                 // The output file size should be significantly reduced

Dit voorbeeld laat zien hoe je een PNG-afbeelding kunt maken met de aangegeven opties, het kunt vullen met een lineaire gradient kleur en het in een bestand kunt opslaan.

string dir = "c:\\temp\\";

                                                                                                                                                Aspose.Imaging.ImageOptions.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                                                                // The number of bits per color channel
                                                                                                                                                createOptions.BitDepth = 8;

                                                                                                                                                // Each pixel is a (red, green, blue) triple followed by the alpha component.
                                                                                                                                                createOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                                                                // The maximum level of compression.
                                                                                                                                                createOptions.CompressionLevel = 9;

                                                                                                                                                // Usage of filters allows to compress continuous tonal images more effectively.
                                                                                                                                                createOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Sub;

                                                                                                                                                // Use progressive loading
                                                                                                                                                createOptions.Progressive = true;

                                                                                                                                                // Create a PNG image with custom parameters.
                                                                                                                                                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);

                                                                                                                                                    // Fill the image with a semi-transparent gradient.
                                                                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                                                                    // Save to a file.
                                                                                                                                                    pngImage.Save(dir + "output.explicitoptions.png");
                                                                                                                                                }

Het volgende voorbeeld toont hoe je een afbeelding in PNG-formaat kunt opslaan met behulp van verschillende opties.

string dir = "c:\\temp\\";

                                                                                                // Create a PNG image of 100x100 px.
                                                                                                // You can also load image of any supported format from a file or a stream.
                                                                                                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);

                                                                                                    // Fill the image with the blue-transparent gradient.
                                                                                                    graphics.FillRectangle(gradientBrush, pngImage.Bounds);

                                                                                                    Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();

                                                                                                    // Progressive loading.
                                                                                                    saveOptions.Progressive = true;

                                                                                                    // Set the horizontal and vertical resolution to 96 pixels per inch.
                                                                                                    saveOptions.ResolutionSettings = new Aspose.Imaging.ResolutionSetting(96.0, 96.0);

                                                                                                    // Each pixel is a (red, green, blue) triple followed by alpha.
                                                                                                    saveOptions.ColorType = Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;

                                                                                                    // Set the maximum level of compression.
                                                                                                    saveOptions.CompressionLevel = 9;

                                                                                                    // This is the best compression, but the slowest execution time.
                                                                                                    // Adaptive filtering means that saving process will choose most sutable filter for each data row.
                                                                                                    saveOptions.FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.Adaptive;

                                                                                                    // The number of bits per channel.
                                                                                                    saveOptions.BitDepth = 8;

                                                                                                    // Save to a file.
                                                                                                    pngImage.Save(dir + "output.png", saveOptions);
                                                                                                }
 Nederlands