Class GifOptions

Class GifOptions

名称: Aspose.Imaging.ImageOptions 收藏: Aspose.Imaging.dll (25.4.0)

图形交换格式(GIF)图像文件创建的API提供开发者全面的选项,以精确地创建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 被加载到一个图像例子,然后出口到多个格式。

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

下面的例子表明如何将多页 vector 图像转换为 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信息,操纵序列并将其重新设置为图像。 为了执行这些操作,此示例创建一个新的图像文件(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.GifOptions 类的新例子。

[JsonConstructor]
public GifOptions()

GifOptions(GifOptions)

启动 Aspose.Imaging.ImageOptions.GifOptions 类的新例子。

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

颜色分辨率 - 每色可用的比特数量到原始图像, minus 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

接收或设置轮数(默认 1 轮)

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 = (Pixel Aspect Ratio + 15) / 64Pixel Aspect Ratio 被定义为 pixel 的比例。宽度超过其高度. 该领域的值范围允许定义最宽的像素 4:1 到最高的像素1:4 以 1/64 的增值。價值 :0 - 不提供任何方面比例信息。1..255 - 在计算中使用的值。

 中文