Class GifOptions

Class GifOptions

Името на пространството: Aspose.Imaging.ImageOptions Асамблея: Aspose.Imaging.dll (25.4.0)

API за графичен формат за обмен (GIF) предлага създаване на файлове с изображенияразработчици обширни опции за генериране на GIF изображения с точностконтрол. с функции, за да зададете цвят на фона, цветна палета, резолюция,междувързан тип, прозрачен цвят, XMP метаданни контейнер, и изображениекомпресия, този API осигурява гъвкавост и ефективност при създаването на оптимизирани визуално привлекателни GIF, адаптирани към специфичните изисквания за приложение.

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

Inheritance

object DisposableObject ImageOptionsBase GifOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

наследници

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

Този пример показва използването на различни класове от SaveOptions Namespace за целите на износа. изображение от типа Gif се зарежда в инстанция на Image и след това се експортира в няколко формати.

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

Следващият пример показва как да се конвертира многостранен вектор на изображение в GIF формат като цяло, без позоваване на конкретен тип изображения.

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

Този пример показва как да изтеглите информация Pixel в Array of Type Color, да манипулирате array и да я върнете към изображението.За да изпълните тези операции, този пример създава нов файл Image (в GIF формат) uisng 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()

Иницијализира нова инстанция на Aspose.Imaging.ImageOptions.GifOption клас.

[JsonConstructor]
public GifOptions()

GifOptions(GifOptions)

Иницијализира нова инстанция на Aspose.Imaging.ImageOptions.GifOption клас.

public GifOptions(GifOptions gifOptions)

Parameters

gifOptions GifOptions

Опции за GIF.

Properties

BackgroundColor

Получава или поставя цветовете на фона.

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

стойност на имота

Color

BackgroundColorIndex

Получава или задава индекса на цветовете на фона на GIF.

public byte BackgroundColorIndex { get; set; }

стойност на имота

byte

ColorResolution

Получава или задава цветовата резолюция GIF.

public byte ColorResolution { get; set; }

стойност на имота

byte

Examples

Този пример показва как да се запази BMP изображение в GIF формат, като се използват различни опции.

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

Резолюция на цветовете - брой битове по първичен цвятна оригиналната картина, минус 1. Тази стойност представлява размера нацялата палитра, от която цветовете в графиката саИзбрани, не броят на цветовете, които действително се използват в графиката.Например, ако стойността в това поле е 3, тогава палетата наоригиналната картина имаше 4 бита на първичен цвят, достъпни за създаванеТази стойност трябва да бъде зададена, за да се посочи богатството наОригиналната палитра, дори ако не всеки цвят от цялотоПалетата е на разположение на източната машина.

DoPaletteCorrection

Получава или задава стойност, която показва дали се прилага корекция на палета.

public bool DoPaletteCorrection { get; set; }

стойност на имота

bool

Examples

Този пример показва как да се запази BMP изображение в GIF формат, като се използват различни опции.

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

Палетната корекция означава, че всеки път, когато изображението се експортира към GIF, цветовете на източника ще бъдат анализирани.за изграждане на най-добрата палета за съответствие (в случай, че изображението Палет не съществува или не е посочено в опциите).Процесът на анализ отнема известно време, но изходната картина ще има най-добрата палетка от цветове и резултатът е визуално по-добър.

HasTrailer

Получава или задава стойност, която показва дали GIF има трейлър.

public bool HasTrailer { get; set; }

стойност на имота

bool

HasTransparentColor

Получава или задава стойност, която показва дали GIF изображението има прозрачен цвят.Ако стойността на връщането е нула, тази собственост се преобладава от контекста на източника на изображението.

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

стойност на имота

bool ?

Interlaced

Това е вярно, ако изображението трябва да бъде взаимосвързано.

public bool Interlaced { get; set; }

стойност на имота

bool

Examples

Този пример показва как да се запази BMP изображение в GIF формат, като се използват различни опции.

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

Получава или задава стойност, която показва дали входът в палетата е сортиран.

public bool IsPaletteSorted { get; set; }

стойност на имота

bool

LoopsCount

Получава или задава броя на лоповете (Default 1 loop)

public int LoopsCount { get; set; }

стойност на имота

int

MaxDiff

Получава или поставя максималната разрешена разлика на пиксела.Ако е по-голяма от нулата, ще се използва компресия за загуба.Препоръчителната стойност за оптимално компресиране на загубите е 80. 30 е много леко, 200 е тежко.Тя работи най-добре, когато се въвеждат само малки загуби, и поради ограничаването на алгоритъма на компресия много високи нива на загуба няма да даде толкова печалба.Размерът на допустимите стойности е [0, 1000].

public int MaxDiff { get; set; }

стойност на имота

int

Examples

Този пример показва как да се запази BMP изображение в GIF формат, като се използват различни опции.

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

Получава или задава GIF пиксел аспект съотношение.

public byte PixelAspectRatio { get; set; }

стойност на имота

byte

Remarks

Pixel Aspect Ratio – фактор, използван за изчисляване на приближениетосъотношението на аспекта на пиксела в оригиналната картина.стойността на полето не е 0, това приближаване на съотношението аспектИзчислено е въз основа на формулата:Aspect Ratio = (Пиксел аспект съотношение + 15) / 64Pixel Aspect Ratio се определя като коефициент на пиксела.ширината над височината му. диапазонът на стойността в това поле позволяваСпецификация на най-широкия пиксел от 4:1 до по-високия1:4 в увеличението на 1/64.Стойностите :0 - Не се предоставя информация за аспектите.1..255 - стойност, използвана в изчислението.

 Български