Class GifOptions
Nazwa przestrzeń: Aspose.Imaging.ImageOptions Zgromadzenie: Aspose.Imaging.dll (25.4.0)
API for Graphical Interchange Format (GIF) oferuje tworzenie plików graficznychTwórcy kompleksowych opcji generowania obrazów GIF z dokładnościąz funkcjami do ustawienia koloru tła, palety kolorów, rozdzielczości,typ powiązany, kolor przejrzysty, kontener metadanych XMP i obrazkompresja, ta API zapewnia elastyczność i wydajność w tworzeniu zoptymalizowanychi wizualnie atrakcyjne GIF dostosowane do specyficznych wymagań aplikacji.
[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← GifOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Dziedziczeni członkowie
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
Ten przykład pokazuje wykorzystanie różnych klas z SaveOptions Namespace do celów eksportowych. obraz typu Gif jest pobierany do instancji obrazu, a następnie wyeksportowany do kilku formatów.
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));
}
Poniższy przykład pokazuje, jak konwertować obraz wektorów wielokierunkowych do formatu GIF w sposób ogólny bez odniesienia do danego typu obrazu.
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);
}
Ten przykład pokazuje, jak pobierać informacje o pikselach w Array typu Koloru, manipulować array i ustawić je z powrotem na obraz. Aby wykonać te czynności, ten przykład tworzy nowy plik obrazu (w formacie GIF) uisng Obiekt 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()
Inicjalizuje nową instancję klasy Aspose.Imaging.ImageOptions.GifOption.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Inicjalizuje nową instancję klasy Aspose.Imaging.ImageOptions.GifOption.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
Opcje GIF.
Properties
BackgroundColor
Dostęp lub ustaw kolor tła.
[JsonProperty]
public Color BackgroundColor { get; set; }
Wartość nieruchomości
BackgroundColorIndex
Pobierz lub ustawić indeks kolorów tła GIF.
public byte BackgroundColorIndex { get; set; }
Wartość nieruchomości
ColorResolution
Pobierz lub ustawić rozdzielczość kolorów GIF.
public byte ColorResolution { get; set; }
Wartość nieruchomości
Examples
Ten przykład pokazuje, jak zaoszczędzić obraz BMP do formatu GIF za pomocą różnych opcji.
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
Rozdzielczość koloru - liczba bitów na kolor pierwotny dostępnado oryginalnego obrazu, minus 1. ta wartość reprezentuje wielkośćcała paleta, z której kolory w grafice byływybrane, nie liczba kolorów faktycznie używanych w grafice.Na przykład, jeśli wartość w tym polu wynosi 3, to paletaoryginalny obraz miał 4 bitów na pierwotny kolor dostępny do tworzeniaWartość ta powinna być ustawiona w celu wskazania bogactwaOryginalna paleta, nawet jeśli nie każda kolor z całegoPaleta jest dostępna na maszyny źródłowej.
DoPaletteCorrection
Otrzymuje lub ustawia wartość wskazującą, czy zastosowana jest poprawka palety.
public bool DoPaletteCorrection { get; set; }
Wartość nieruchomości
Examples
Ten przykład pokazuje, jak zaoszczędzić obraz BMP do formatu GIF za pomocą różnych opcji.
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
Korekcja palety oznacza, że za każdym razem, gdy obraz jest eksportowany do GIF, kolor obrazu źródłowego zostanie analizowany.aby zbudować najlepszą paletę dopasowaną (w przypadku, gdy paleta obrazu nie istnieje lub nie jest określona w opcjach).Proces analizy zajmuje trochę czasu, jednak obraz wyjścia będzie miał najlepszą paletę kolorów, a wynik jest wizualnie lepszy.
HasTrailer
Otrzymuje lub ustawia wartość wskazującą, czy GIF ma trailer.
public bool HasTrailer { get; set; }
Wartość nieruchomości
HasTransparentColor
Otrzymuje lub ustawia wartość wskazującą, czy obraz GIF ma przejrzysty kolor.Jeżeli wartość zwrotu jest zeroWłaściwość ta przewyższona jest kontekstem obrazu źródłowego.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
Wartość nieruchomości
bool ?
Interlaced
Prawda jest taka, że obraz powinien być połączony.
public bool Interlaced { get; set; }
Wartość nieruchomości
Examples
Ten przykład pokazuje, jak zaoszczędzić obraz BMP do formatu GIF za pomocą różnych opcji.
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
Otrzymuje lub ustawia wartość wskazującą, czy wpisy palety są wyrównane.
public bool IsPaletteSorted { get; set; }
Wartość nieruchomości
LoopsCount
Otrzymuje lub ustawia liczbę łupów (Default 1 loop)
public int LoopsCount { get; set; }
Wartość nieruchomości
MaxDiff
Otrzymuje lub ustawia maksymalną dopuszczalną różnicę pikseli.Jeśli jest większa niż zero, zostanie zastosowana kompresja straty.Zalecana wartość dla optymalnej kompresji straty wynosi 80. 30 jest bardzo lekka kompresja, 200 jest ciężka.Działa najlepiej, gdy wprowadzono tylko niewielkie straty, a ze względu na ograniczenie algorytmu kompresji bardzo wysokie poziomy strat nie dają tak dużo zysku.Różnica dopuszczalnych wartości wynosi [0, 1000].
public int MaxDiff { get; set; }
Wartość nieruchomości
Examples
Ten przykład pokazuje, jak zaoszczędzić obraz BMP do formatu GIF za pomocą różnych opcji.
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
Otrzymuje lub ustawia stosunek widzenia piksela GIF.
public byte PixelAspectRatio { get; set; }
Wartość nieruchomości
Remarks
Pixel Aspect Ratio – współczynnik wykorzystywany do obliczania przybliżeniaz punktu widzenia stosunku piksela w oryginalnym obrazie. jeśliwartość pola nie jest 0, to przybliżenie stosunku aspektuJest obliczany na podstawie formuły:Aspect Ratio = (Pixel Aspect Ratio + 15) / 64Pixel Aspect Ratio jest zdefiniowany jako współczynnik piksela.szerokość nad jego wysokością. zakres wartości w tym polu pozwalaspecyfikacja najszerszego piksela od 4:1 do najwyższego piksela1:4 w podwyżkach 1/64.Wartości :0 - Informacje o stosunku aspektowym nie są podane.1..255 - Wartość wykorzystywana w obliczeniach.