Class GifOptions
Der Name: Aspose.Imaging.ImageOptions Versammlung: Aspose.Imaging.dll (25.4.0)
Die API für Graphical Interchange Format (GIF) Raster Image File Creation bietetEntwickler umfassende Optionen für die Erzeugung von GIF-Bilder mit Präzisionmit Funktionen, um Hintergrundfarbe, Farbpalette, Auflösung,Interlinktyp, transparente Farbe, XMP Metadatenbehälter und BildKompression, diese API gewährleistet Flexibilität und Effizienz bei der Erstellung optimiertund visuell attraktive GIFs, die an spezifische Anwendungsanforderungen angepasst sind.
[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← GifOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Vererbte Mitglieder
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
Dieses Beispiel zeigt die Verwendung verschiedener Klassen aus SaveOptions Namespace für Exportzwecke. Ein Gif-Bild wird in eine Image-Instanz hochgeladen und dann in mehrere Formate exportiert.
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));
}
Das folgende Beispiel zeigt, wie man ein mehrseiten Vektorbild in GIF-Format im Allgemeinen konvertiert, ohne auf einen bestimmten Bildtyp zu beziehen.
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);
}
Dieses Beispiel zeigt, wie Sie Pixel-Informationen in einer Array von Typfarbe laden, die Array manipulieren und wieder auf das Bild setzen.Um diese Operationen durchzuführen, erstellt dieses Beispiel eine neue Bilddatei (in GIF-Format) uisng MemoryStream Objekt.
//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()
Initialisiert eine neue Instanz der Aspose.Imaging.ImageOptions.GifOptions Klasse.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Initialisiert eine neue Instanz der Aspose.Imaging.ImageOptions.GifOptions Klasse.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
Die GIF Optionen.
Properties
BackgroundColor
Sie erhalten oder legen die Hintergrundfarbe fest.
[JsonProperty]
public Color BackgroundColor { get; set; }
Eigentumswert
BackgroundColorIndex
Erhalten oder festlegen Sie den GIF Hintergrundfarbeindex.
public byte BackgroundColorIndex { get; set; }
Eigentumswert
ColorResolution
Erhalten oder festlegen Sie die GIF-Farblösung.
public byte ColorResolution { get; set; }
Eigentumswert
Examples
Dieses Beispiel zeigt, wie man ein BMP-Bild in GIF-Format mit verschiedenen Optionen speichert.
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
Farblösung - Anzahl von Bits pro primäre Farbe verfügbarzum ursprünglichen Bild, minus 1. Dieser Wert stellt die Größe desdie ganze Palette, aus der die Farben im Grafikausgewählt, nicht die Anzahl der Farben, die tatsächlich in der Grafik verwendet werden.Zum Beispiel, wenn der Wert in diesem Feld 3 ist, dann ist die PaletteDas ursprüngliche Bild hatte 4 Bits pro primäre Farbe zur Erstellung verfügbarDieser Wert sollte festgelegt werden, um die Reichtum derdie ursprüngliche Palette, auch wenn nicht jede Farbe aus der ganzenPalette ist auf der Quellmaschine verfügbar.
DoPaletteCorrection
Er erhält oder stellt einen Wert an, der darauf hindeutet, ob eine Palettkorrektur angewendet wird.
public bool DoPaletteCorrection { get; set; }
Eigentumswert
Examples
Dieses Beispiel zeigt, wie man ein BMP-Bild in GIF-Format mit verschiedenen Optionen speichert.
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
Palettenkorrektur bedeutet, dass jedes Mal, wenn das Bild in GIF exportiert wird, die Quellbildfarben analysiert werden.um die beste matching palette zu erstellen (in dem Fall, dass Bild palette nicht existiert oder nicht in den optionen angegeben ist).Der Analyse-Prozess dauert einige Zeit, aber das Ausgangsbild hat die beste Farbpalette und das Ergebnis ist visuell besser.
HasTrailer
Gibt oder setzt einen Wert, der darauf hindeutet, ob GIF einen Trailer hat.
public bool HasTrailer { get; set; }
Eigentumswert
HasTransparentColor
Er bekommt oder setzt einen Wert, der angibt, ob ein GIF-Bild transparente Farbe hat.Wenn der Rückerstattungswert Null, diese Eigenschaft wird durch den Quellbildkontext übertrieben.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
Eigentumswert
bool ?
Interlaced
Es ist wahr, wenn das Bild vernetzt werden sollte.
public bool Interlaced { get; set; }
Eigentumswert
Examples
Dieses Beispiel zeigt, wie man ein BMP-Bild in GIF-Format mit verschiedenen Optionen speichert.
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
Er bekommt oder setzt einen Wert, der darauf hindeutet, ob Palette-Einträge sortiert werden.
public bool IsPaletteSorted { get; set; }
Eigentumswert
LoopsCount
Erhalten oder setzen die Laufzahlen (Default 1 Lauf)
public int LoopsCount { get; set; }
Eigentumswert
MaxDiff
Erhalten oder setzen die maximale erlaubte Pixel Differenz. Wenn größer als Null, wird die Verluste Kompression verwendet werden.Der empfohlene Wert für die optimale Verlustkompression ist 80. 30 ist sehr leichte Kompression, 200 ist schwer.Es funktioniert am besten, wenn nur kleine Verluste eingeführt werden, und aufgrund der Einschränkung des Komprimierungsalgoritms werden sehr hohe Verlustewerte nicht so viel Gewinn geben.Die Anzahl der zulässigen Werte ist [0, 1000].
public int MaxDiff { get; set; }
Eigentumswert
Examples
Dieses Beispiel zeigt, wie man ein BMP-Bild in GIF-Format mit verschiedenen Optionen speichert.
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
Erhalten oder festlegen Sie das GIF Pixel Aspektverhältnis.
public byte PixelAspectRatio { get; set; }
Eigentumswert
Remarks
Pixel Aspect Ratio - Faktor, der zur Berechnung einer Umgebung verwendet wirdder Aspektverhältnis des Pixels im ursprünglichen Bild.Wert des Feldes ist nicht 0, diese Verhältnis des AspektsEs wird auf der Grundlage der Formel berechnet:Aspekt Ratio = (Pixel Aspekt Ratio + 15) / 64Die Pixel Aspect Ratio wird als Quotient des Pixels definiert.Breite über seine Höhe. Das Wertbereich in diesem Feld ermöglichtSpezifikation des breitesten Pixels von 4:1 bis zum höchsten Pixel1:4 in Erhöhungen von 1/64th.Die Werte:0 - Es wird keine Aspektverhältnisinformationen gegeben.1..255 - Wert, der in der Berechnung verwendet wird.