Class GifOptions
De naam: Aspose.Imaging.ImageOptions Verzameling: Aspose.Imaging.dll (25.4.0)
De API voor Graphical Interchange Format (GIF) raster beeldbestand creatie biedtontwikkelaars uitgebreide opties voor het genereren van GIF-beelden met nauwkeurigheidmet functies om achtergrondkleur, kleurpalet, resolutie,met elkaar verbonden type, transparante kleur, XMP metadata container en afbeeldingCompression, deze API zorgt voor flexibiliteit en efficiëntie bij het creëren van geoptimaliseerdeen visueel aantrekkelijke GIF’s aangepast aan specifieke toepassingsvereisten.
[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← GifOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Geëerbiede leden
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
Dit voorbeeld toont het gebruik van verschillende klassen van SaveOptions Namespace voor exportdoeleinden.Een Gif-beeld wordt in een beeldinstantie geladen en vervolgens naar meerdere formaten uitgevoerd.
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));
}
Het volgende voorbeeld laat zien hoe je een multipage vector beeld in GIF-formaat over het algemeen kunt converteren zonder verwijzing naar een specifiek beeldtype.
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);
}
Dit voorbeeld laat zien hoe u Pixel-informatie in een Array van Type Color laden, de array manipuleren en terug instellen naar de afbeelding. Om deze operaties uit te voeren creëert dit voorwerp een nieuwe Image-bestand (in GIF-formaat) uisng MemoryStream-object.
//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()
Initialiseert een nieuwe instantie van de Aspose.Imaging.ImageOptions.Gifoptions klasse.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Initialiseert een nieuwe instantie van de Aspose.Imaging.ImageOptions.Gifoptions klasse.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
De GIF opties.
Properties
BackgroundColor
Geeft of zet de achtergrondkleur.
[JsonProperty]
public Color BackgroundColor { get; set; }
Eigendomswaarde
BackgroundColorIndex
Geeft of stelt de GIF achtergrondkleurindex.
public byte BackgroundColorIndex { get; set; }
Eigendomswaarde
ColorResolution
Geeft of instelt de GIF-kleurresolutie.
public byte ColorResolution { get; set; }
Eigendomswaarde
Examples
Dit voorbeeld laat zien hoe je een BMP-afbeelding kunt opslaan in GIF-formaat met behulp van verschillende opties.
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
Color Resolution - Aantal bits per primaire kleur beschikbaarop de oorspronkelijke afbeelding, minus 1. deze waarde vertegenwoordigt de grootte van dede hele palet waaruit de kleuren in de grafiek warengeselecteerd, niet het aantal kleuren dat daadwerkelijk wordt gebruikt in de grafiek.Bijvoorbeeld, als de waarde in dit veld 3 is, dan is de palet vande oorspronkelijke afbeelding had 4 bits per primaire kleur beschikbaar om te makenDeze waarde moet worden ingesteld om de rijkdom van dede oorspronkelijke palet, zelfs als niet elke kleur van het geheelPalet is beschikbaar op de bronmachine.
DoPaletteCorrection
Geeft of zet een waarde die aangeeft of een paletcorrectie wordt toegepast.
public bool DoPaletteCorrection { get; set; }
Eigendomswaarde
Examples
Dit voorbeeld laat zien hoe je een BMP-afbeelding kunt opslaan in GIF-formaat met behulp van verschillende opties.
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
Paletcorrectie betekent dat wanneer de afbeelding naar GIF wordt geëxporteerd, de bronbeeldkleuren worden geanalyseerd.om de beste matching palet te bouwen (in het geval dat de beeldpalet niet bestaat of niet wordt vermeld in de opties).Het analyseproces duurt een tijd, maar het uitgangsbeeld heeft de beste kleurpalet en het resultaat is visueel beter.
HasTrailer
Geeft of zet een waarde die aangeeft of GIF een trailer heeft.
public bool HasTrailer { get; set; }
Eigendomswaarde
HasTransparentColor
Geeft of stelt een waarde aan die aanwijst of een GIF-afbeelding transparante kleur heeft.Als de terugkeerwaarde Null, deze eigenschap wordt overgedragen door de bron beeld context.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
Eigendomswaarde
bool ?
Interlaced
Het is waar als de afbeelding moet worden geïntegreerd.
public bool Interlaced { get; set; }
Eigendomswaarde
Examples
Dit voorbeeld laat zien hoe je een BMP-afbeelding kunt opslaan in GIF-formaat met behulp van verschillende opties.
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
Geeft of stelt een waarde aan die aangeeft of de palet-inschrijvingen gesorteerd zijn.
public bool IsPaletteSorted { get; set; }
Eigendomswaarde
LoopsCount
Gets of sets the loops count (Default 1 loop)
public int LoopsCount { get; set; }
Eigendomswaarde
MaxDiff
Geeft of stelt de maximale toegestane pixelafwijk.Als groter is dan nul, wordt verliescompressie gebruikt.De aanbevolen waarde voor optimale verliescompressie is 80. 30 is zeer lichtcompressie, 200 is zwaar.Het werkt het beste wanneer slechts een kleine verlies wordt geïntroduceerd, en vanwege de beperking van het compressiealgoritme zeer hoge verlies niveaus zullen niet zo veel winst geven.Het bereik van toegestane waarden is [0, 1000].
public int MaxDiff { get; set; }
Eigendomswaarde
Examples
Dit voorbeeld laat zien hoe je een BMP-afbeelding kunt opslaan in GIF-formaat met behulp van verschillende opties.
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
Geeft of stelt de GIF pixel aspect ratio.
public byte PixelAspectRatio { get; set; }
Eigendomswaarde
Remarks
Pixel Aspect Ratio - Factor gebruikt om een benadering te berekenenvan het aspectpercentage van de pixel in de oorspronkelijke afbeelding.de waarde van het veld is niet 0, deze benadering van het aspect ratioHet wordt berekend op basis van de formule:Aspect Ratio = (Pixel Aspect Ratio + 15) / 64De Pixel Aspect Ratio wordt gedefinieerd als de coeent van de pixels.de breedte boven de hoogte. de waarde-range in dit veld toestaatspecificatie van de breedste pixel van 4:1 tot de hoogste pixel van1:4 in verhogingen van 1/64.De waarden :0 - Geen aspect ratio informatie wordt gegeven.1..255 - De waarde die wordt gebruikt in de berekening.