Class GifOptions

Class GifOptions

Il nome: Aspose.Imaging.ImageOptions Assemblea: Aspose.Imaging.dll (25.4.0)

L’API per la creazione di file di immagini di raster Graphical Interchange Format (GIF) offresviluppatori opzioni complete per generare immagini GIF con precisioneCon funzionalità per impostare colore di sfondo, palette di colori, risoluzione,Tipo interlinkato, colore trasparente, contenitore di metadati XMP e immagineCompressione, questa API assicura flessibilità ed efficienza nella creazione di ottimizzatie GIF visualmente attraenti adattati ai requisiti di applicazione specifici.

[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable

Inheritance

object DisposableObject ImageOptionsBase GifOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

I membri ereditari

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

Questo esempio dimostra l’uso di diverse classi da SaveOptions Namespace per scopi di esportazione. Un’immagine del tipo Gif viene caricata in un esempio di Immagine e poi esportata a diversi formati.

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));
                                                                                                                                                                                                                    }

L’esempio seguente mostra come convertire un’immagine vector multipagine in formato GIF in generale senza fare riferimento a un particolare tipo di immagine.

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.gif");

                                                                                                                                                           Aspose.Imaging.ImageOptionsBase exportOptions = new Aspose.Imaging.ImageOptions.GifOptions();

                                                                                                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFilePath))
                                                                                                                                                           {
                                                                                                                                                               exportOptions.MultiPageOptions = null;

                                                                                                                                                               // Export only first two pages. These pages will be presented as animated frames in the output GIF.
                                                                                                                                                               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);
                                                                                                                                                           }

Questo esempio mostra come caricare le informazioni di Pixel in un Array di Tipo di colore, manipola l’array e la mette indietro all’immagine.Per eseguire queste operazioni, questo esempio crea un nuovo file di Immagine (in formato GIF) uisng oggetto MemoryStream.

//Create an instance of MemoryStream
                                                                                                                                                                                                                                                         using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                                             //Create an instance of GifOptions and set its various properties including the Source property
                                                                                                                                                                                                                                                             Aspose.Imaging.ImageOptions.GifOptions gifOptions = new Aspose.Imaging.ImageOptions.GifOptions();
                                                                                                                                                                                                                                                             gifOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

                                                                                                                                                                                                                                                             //Create an instance of Image
                                                                                                                                                                                                                                                             using (Aspose.Imaging.RasterImage image = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Create(gifOptions, 500, 500))
                                                                                                                                                                                                                                                             {
                                                                                                                                                                                                                                                                 //Get the pixels of image by specifying the area as image boundary
                                                                                                                                                                                                                                                                 Aspose.Imaging.Color[] pixels = image.LoadPixels(image.Bounds);

                                                                                                                                                                                                                                                                 //Loop over the Array and sets color of alrenative indexed pixel
                                                                                                                                                                                                                                                                 for (int index = 0; index < pixels.Length; index++)
                                                                                                                                                                                                                                                                 {
                                                                                                                                                                                                                                                                     if (index % 2 == 0)
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                         //Set the indexed pixel color to yellow
                                                                                                                                                                                                                                                                         pixels[index] = Aspose.Imaging.Color.Yellow;
                                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                                     else
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                         //Set the indexed pixel color to blue
                                                                                                                                                                                                                                                                         pixels[index] = Aspose.Imaging.Color.Blue;
                                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                                 }

                                                                                                                                                                                                                                                                 //Apply the pixel changes to the image
                                                                                                                                                                                                                                                                 image.SavePixels(image.Bounds, pixels);

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

                                                                                                                                                                                                                                                             // Write MemoryStream to File
                                                                                                                                                                                                                                                             using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C:\temp\output.gif", System.IO.FileMode.Create))
                                                                                                                                                                                                                                                             {
                                                                                                                                                                                                                                                                 stream.WriteTo(fileStream);
                                                                                                                                                                                                                                                             }   
                                                                                                                                                                                                                                                         }

Constructors

GifOptions()

Inizia una nuova instanza della classe Aspose.Imaging.ImageOptions.GifOption.

[JsonConstructor]
public GifOptions()

GifOptions(GifOptions)

Inizia una nuova instanza della classe Aspose.Imaging.ImageOptions.GifOption.

public GifOptions(GifOptions gifOptions)

Parameters

gifOptions GifOptions

Le opzioni GIF.

Properties

BackgroundColor

Riceve o impone il colore di sfondo.

[JsonProperty]
public Color BackgroundColor { get; set; }

Valore di proprietà

Color

BackgroundColorIndex

Riceve o imposta l’indice di colore di sfondo GIF.

public byte BackgroundColorIndex { get; set; }

Valore di proprietà

byte

ColorResolution

Riceve o impone la risoluzione del colore GIF.

public byte ColorResolution { get; set; }

Valore di proprietà

byte

Examples

Questo esempio mostra come salvare un’immagine BMP in formato GIF utilizzando varie opzioni.

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

                                                                                          using (Aspose.Imaging.Image bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(1000, 1000))
                                                                                          {
                                                                                              // Fill the entire image with the blue-yellow gradient.
                                                                                              Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
                                                                                                      new Aspose.Imaging.Point(0, 0),
                                                                                                      new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
                                                                                                      Aspose.Imaging.Color.Blue,
                                                                                                      Aspose.Imaging.Color.Yellow);

                                                                                              Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(bmpImage);
                                                                                              graphics.FillRectangle(gradientBrush, bmpImage.Bounds);

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

                                                                                              // The number of bits required to store a color, minus 1.
                                                                                              saveOptions.ColorResolution = 7;

                                                                                              // Palette correction means that whenever image is exported to GIF the source image colors will be analyzed
                                                                                              // in order to build the best matching palette (in case image Palette does not exist or not specified in the options)
                                                                                              saveOptions.DoPaletteCorrection = true;

                                                                                              // Load a GIF image in a progressive way.
                                                                                              // An interlaced GIF doesn't display its scanlines linearly from top to bottom, but instead reorders it
                                                                                              // so the content of the GIF becomes clear even before it finishes loading.
                                                                                              saveOptions.Interlaced = true;

                                                                                              // Save as a lossless GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossless GIF: {0} bytes.", stream.Length);
                                                                                              }

                                                                                              // Set the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
                                                                                              // The recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
                                                                                              saveOptions.MaxDiff = 80;

                                                                                              // Save as a lossy GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.lossy.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossy GIF: {0} bytes.", stream.Length);
                                                                                              }
                                                                                          }

                                                                                          //The output may look like this:
                                                                                          //The size of the lossless GIF: 212816 bytes.
                                                                                          //The size of the lossy GIF: 89726 bytes.

Remarks

Risoluzione del colore - Numero di bit per colore primario disponibileper l’immagine originale, minus 1.Questo valore rappresenta la dimensione dil’intera paletta da cui i colori nel grafico eranoselezionato, non il numero di colori effettivamente utilizzati nel grafico.Ad esempio, se il valore in questo campo è 3, allora la paletta dil’immagine originale aveva 4 bit per colore primario disponibile per creareQuesto valore deve essere impostato per indicare la ricchezza dila paletta originale, anche se non ogni colore dell’interoLa paletta è disponibile sulla macchina sorgente.

DoPaletteCorrection

Riceve o impone un valore che indica se viene applicata la correzione della paletta.

public bool DoPaletteCorrection { get; set; }

Valore di proprietà

bool

Examples

Questo esempio mostra come salvare un’immagine BMP in formato GIF utilizzando varie opzioni.

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

                                                                                          using (Aspose.Imaging.Image bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(1000, 1000))
                                                                                          {
                                                                                              // Fill the entire image with the blue-yellow gradient.
                                                                                              Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
                                                                                                      new Aspose.Imaging.Point(0, 0),
                                                                                                      new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
                                                                                                      Aspose.Imaging.Color.Blue,
                                                                                                      Aspose.Imaging.Color.Yellow);

                                                                                              Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(bmpImage);
                                                                                              graphics.FillRectangle(gradientBrush, bmpImage.Bounds);

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

                                                                                              // The number of bits required to store a color, minus 1.
                                                                                              saveOptions.ColorResolution = 7;

                                                                                              // Palette correction means that whenever image is exported to GIF the source image colors will be analyzed
                                                                                              // in order to build the best matching palette (in case image Palette does not exist or not specified in the options)
                                                                                              saveOptions.DoPaletteCorrection = true;

                                                                                              // Load a GIF image in a progressive way.
                                                                                              // An interlaced GIF doesn't display its scanlines linearly from top to bottom, but instead reorders it
                                                                                              // so the content of the GIF becomes clear even before it finishes loading.
                                                                                              saveOptions.Interlaced = true;

                                                                                              // Save as a lossless GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossless GIF: {0} bytes.", stream.Length);
                                                                                              }

                                                                                              // Set the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
                                                                                              // The recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
                                                                                              saveOptions.MaxDiff = 80;

                                                                                              // Save as a lossy GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.lossy.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossy GIF: {0} bytes.", stream.Length);
                                                                                              }
                                                                                          }

                                                                                          //The output may look like this:
                                                                                          //The size of the lossless GIF: 212816 bytes.
                                                                                          //The size of the lossy GIF: 89726 bytes.

Remarks

La correzione di palette significa che ogni volta che l’immagine viene esportata al GIF, i colori dell’immagine sorgente saranno analizzati.per costruire la migliore paletta corrispondente (nel caso in cui la paletta immagine non esiste o non è specificata nelle opzioni).Il processo di analisi richiede un po ‘di tempo, tuttavia l’immagine di uscita avrà la migliore paletta di colori che corrisponde e il risultato è visivamente migliore.

HasTrailer

Riceve o impone un valore che indica se GIF ha un trailer.

public bool HasTrailer { get; set; }

Valore di proprietà

bool

HasTransparentColor

Riceve o impone un valore che indica se un’immagine GIF ha un colore trasparente.Se il valore di ritorno è Null, questa proprietà è sovrapposata dal contesto immagine sorgente.

[JsonProperty]
public bool? HasTransparentColor { get; set; }

Valore di proprietà

bool ?

Interlaced

È vero se l’immagine dovrebbe essere interligata.

public bool Interlaced { get; set; }

Valore di proprietà

bool

Examples

Questo esempio mostra come salvare un’immagine BMP in formato GIF utilizzando varie opzioni.

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

                                                                                          using (Aspose.Imaging.Image bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(1000, 1000))
                                                                                          {
                                                                                              // Fill the entire image with the blue-yellow gradient.
                                                                                              Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
                                                                                                      new Aspose.Imaging.Point(0, 0),
                                                                                                      new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
                                                                                                      Aspose.Imaging.Color.Blue,
                                                                                                      Aspose.Imaging.Color.Yellow);

                                                                                              Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(bmpImage);
                                                                                              graphics.FillRectangle(gradientBrush, bmpImage.Bounds);

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

                                                                                              // The number of bits required to store a color, minus 1.
                                                                                              saveOptions.ColorResolution = 7;

                                                                                              // Palette correction means that whenever image is exported to GIF the source image colors will be analyzed
                                                                                              // in order to build the best matching palette (in case image Palette does not exist or not specified in the options)
                                                                                              saveOptions.DoPaletteCorrection = true;

                                                                                              // Load a GIF image in a progressive way.
                                                                                              // An interlaced GIF doesn't display its scanlines linearly from top to bottom, but instead reorders it
                                                                                              // so the content of the GIF becomes clear even before it finishes loading.
                                                                                              saveOptions.Interlaced = true;

                                                                                              // Save as a lossless GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossless GIF: {0} bytes.", stream.Length);
                                                                                              }

                                                                                              // Set the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
                                                                                              // The recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
                                                                                              saveOptions.MaxDiff = 80;

                                                                                              // Save as a lossy GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.lossy.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossy GIF: {0} bytes.", stream.Length);
                                                                                              }
                                                                                          }

                                                                                          //The output may look like this:
                                                                                          //The size of the lossless GIF: 212816 bytes.
                                                                                          //The size of the lossy GIF: 89726 bytes.

IsPaletteSorted

Riceve o impone un valore che indica se le entrate di palette sono classificate.

public bool IsPaletteSorted { get; set; }

Valore di proprietà

bool

LoopsCount

Riceve o impone il conteggio dei lotti (Default 1 loop)

public int LoopsCount { get; set; }

Valore di proprietà

int

MaxDiff

Riceve o impone la differenza di pixel massima consentita.Se è maggiore di zero, verrà utilizzata la compressione perdita.Il valore raccomandato per la compressione ottimale della perdita è 80. 30 è compressione molto leggera, 200 è pesante.Funziona meglio quando viene introdotta solo una piccola perdita, e a causa della limitazione dell’algoritmo di compressione i livelli di perdita molto alti non daranno tanto guadagno.La gamma di valori consentiti è [0, 1000].

public int MaxDiff { get; set; }

Valore di proprietà

int

Examples

Questo esempio mostra come salvare un’immagine BMP in formato GIF utilizzando varie opzioni.

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

                                                                                          using (Aspose.Imaging.Image bmpImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(1000, 1000))
                                                                                          {
                                                                                              // Fill the entire image with the blue-yellow gradient.
                                                                                              Aspose.Imaging.Brushes.LinearGradientBrush gradientBrush = new Aspose.Imaging.Brushes.LinearGradientBrush(
                                                                                                      new Aspose.Imaging.Point(0, 0),
                                                                                                      new Aspose.Imaging.Point(bmpImage.Width, bmpImage.Height),
                                                                                                      Aspose.Imaging.Color.Blue,
                                                                                                      Aspose.Imaging.Color.Yellow);

                                                                                              Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(bmpImage);
                                                                                              graphics.FillRectangle(gradientBrush, bmpImage.Bounds);

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

                                                                                              // The number of bits required to store a color, minus 1.
                                                                                              saveOptions.ColorResolution = 7;

                                                                                              // Palette correction means that whenever image is exported to GIF the source image colors will be analyzed
                                                                                              // in order to build the best matching palette (in case image Palette does not exist or not specified in the options)
                                                                                              saveOptions.DoPaletteCorrection = true;

                                                                                              // Load a GIF image in a progressive way.
                                                                                              // An interlaced GIF doesn't display its scanlines linearly from top to bottom, but instead reorders it
                                                                                              // so the content of the GIF becomes clear even before it finishes loading.
                                                                                              saveOptions.Interlaced = true;

                                                                                              // Save as a lossless GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossless GIF: {0} bytes.", stream.Length);
                                                                                              }

                                                                                              // Set the maximum allowed pixel difference. If greater than zero, lossy compression will be used.
                                                                                              // The recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy.
                                                                                              saveOptions.MaxDiff = 80;

                                                                                              // Save as a lossy GIF.
                                                                                              using (System.IO.Stream stream = System.IO.File.OpenWrite(dir + "output.lossy.gif"))
                                                                                              {
                                                                                                  bmpImage.Save(stream, saveOptions);
                                                                                                  System.Console.WriteLine("The size of the lossy GIF: {0} bytes.", stream.Length);
                                                                                              }
                                                                                          }

                                                                                          //The output may look like this:
                                                                                          //The size of the lossless GIF: 212816 bytes.
                                                                                          //The size of the lossy GIF: 89726 bytes.

PixelAspectRatio

Riceve o impone il rapporto di aspetto del pixel GIF.

public byte PixelAspectRatio { get; set; }

Valore di proprietà

byte

Remarks

Pixel Aspect Ratio – Il fattore utilizzato per calcolare un approcciodel rapporto di aspetto del pixel nell’immagine originale. se ilil valore del campo non è 0, questa approximazione del rapporto di aspettoSi calcola sulla base della formula:Ratio di Aspetto = (Pixel Aspect Ratio + 15) / 64Il Pixel Aspect Ratio è definito come il coeente del pixel.la larghezza sopra la sua altezza. la gamma di valore in questo campo consentela specifica del pixel più ampio di 4:1 al pixel più alto di1:4 in aumento di 1/64.I valori:0 - Nessuna informazione di rapporto di aspetti viene fornita.1..255 - Valore utilizzato nel calcolo.

 Italiano