Class GifOptions
Pôvodný názov: Aspose.Imaging.ImageOptions Zhromaždenie: Aspose.Imaging.dll (25.4.0)
API pre grafický formát výmeny (GIF) raster image file creation ponúkavývojári komplexné možnosti pre generovanie GIF obrázkov s presnosťouovládanie. s funkciami nastaviť farbu pozadia, farebnú paletu, rozlíšenie,prepojený typ, transparentná farba, kontajner metadata XMP a obrázokkompresia, táto API zaisťuje flexibilitu a efektívnosť pri vytváraní optimalizovanýcha vizuálne atraktívne GIF prispôsobené špecifickým požiadavkám aplikácie.
[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← GifOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Z dedičných členov
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
Tento príklad ukazuje použitie rôznych tried z SaveOptions Namespace na exportné účely. obrázok typu Gif sa nahráva do príkladu Obrázok a potom sa vyváža do viacerých formátov.
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));
}
Nasledujúci príklad ukazuje, ako previesť viacstránkový vektorový obrázok do formátu GIF vo všeobecnosti bez odkazu na konkrétny typ 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);
}
Tento príklad ukazuje, ako nahrať informácie o pixeloch v režime typu farby, manipulovať s režimom a nastaviť ho späť na obrázok. Ak chcete vykonať tieto operácie, tento vzor vytvára nový súbor obrazu (v formáte GIF) 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()
Initalizuje novú inštanciu triedy Aspose.Imaging.ImageOptions.GifOption.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Initalizuje novú inštanciu triedy Aspose.Imaging.ImageOptions.GifOption.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
Možnosti GIF.
Properties
BackgroundColor
Získať alebo nastaviť farbu pozadia.
[JsonProperty]
public Color BackgroundColor { get; set; }
Hodnota nehnuteľnosti
BackgroundColorIndex
Získajte alebo nastavíte index farieb pozadia GIF.
public byte BackgroundColorIndex { get; set; }
Hodnota nehnuteľnosti
ColorResolution
Získať alebo nastaviť GIF farebné rozlíšenie.
public byte ColorResolution { get; set; }
Hodnota nehnuteľnosti
Examples
Tento príklad ukazuje, ako uložiť BMP obrázok do formátu GIF pomocou rôznych možností.
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
Farebné rozlíšenie - Počet bitov na primárnu farbu k dispozíciina pôvodný obrázok, minus 1. Táto hodnota predstavuje veľkosťcelá paleta, z ktorej boli farby v grafevybrané, nie počet farieb, ktoré sa v skutočnosti používajú v grafike.Napríklad, ak je hodnota v tomto poli 3, potom paletapôvodný obrázok mal 4 bity na primárnu farbu k dispozícii na vytvorenieTáto hodnota by mala byť nastavená na ukazovanie bohatstvapôvodná paleta, aj keď nie každá farba z celéhoPaleta je k dispozícii na zdrojovej stroji.
DoPaletteCorrection
Získa alebo nastaví hodnotu, ktorá naznačuje, či sa aplikuje korekcia palety.
public bool DoPaletteCorrection { get; set; }
Hodnota nehnuteľnosti
Examples
Tento príklad ukazuje, ako uložiť BMP obrázok do formátu GIF pomocou rôznych možností.
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
Korekcia palety znamená, že vždy, keď je obrázok vyvezený do GIF, sa analyzuje zdrojová farba obrazu.s cieľom vytvoriť najvhodnejšiu paletu (v prípade, že paleta obrazu neexistuje alebo nie je uvedená v možnostiach).Proces analýzy trvá nejaký čas, ale výsledný obrázok bude mať najlepšiu farebnú paletu a výsledok je vizuálne lepší.
HasTrailer
Získajte alebo nastavíte hodnotu, ktorá ukazuje, či GIF má trailer.
public bool HasTrailer { get; set; }
Hodnota nehnuteľnosti
HasTransparentColor
Získa alebo nastaví hodnotu, ktorá ukazuje, či má GIF obrázok transparentnú farbu.Ak je vrátená hodnota nula, táto vlastnosť je prekrývaná zdrojovým kontextom obrazu.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
Hodnota nehnuteľnosti
bool ?
Interlaced
Je pravda, ak by mal byť obrázok prepojený.
public bool Interlaced { get; set; }
Hodnota nehnuteľnosti
Examples
Tento príklad ukazuje, ako uložiť BMP obrázok do formátu GIF pomocou rôznych možností.
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
Získa alebo nastaví hodnotu, ktorá naznačuje, či sú paletové vstupy usporiadané.
public bool IsPaletteSorted { get; set; }
Hodnota nehnuteľnosti
LoopsCount
Získajte alebo nastavíte počítanie loops (Default 1 loop)
public int LoopsCount { get; set; }
Hodnota nehnuteľnosti
MaxDiff
Získať alebo nastaviť maximálny povolený rozdiel pixelov. Ak je väčší ako nula, straty kompresie sa použije.Odporúčaná hodnota pre optimálnu kompresiu straty je 80. 30 je veľmi ľahká kompresiu, 200 je ťažká.Najlepšie funguje, keď sa zavádza len malá strata, a kvôli obmedzeniu algoritmu kompresie veľmi vysoké úrovne straty nedajú toľko ziskov.Rozsah povolených hodnôt je [0, 1000].
public int MaxDiff { get; set; }
Hodnota nehnuteľnosti
Examples
Tento príklad ukazuje, ako uložiť BMP obrázok do formátu GIF pomocou rôznych možností.
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
Získať alebo nastaviť GIF pixel aspekt pomeru.
public byte PixelAspectRatio { get; set; }
Hodnota nehnuteľnosti
Remarks
Pixel Aspect Ratio - faktor používaný na výpočet približeniaz hľadiska vzťahu pixelov v pôvodnom obraze. akhodnota poľa nie je 0, táto približnosť aspektového pomeruVypočíta sa na základe vzorce:Aspect Ratio = (Pixel Aspect Ratio + 15) / 64Pixel Aspect Ratio je definovaný ako koeficient pixelov.šírka nad jeho výškou. rozsah hodnoty v tomto poli umožňuješpecifikácia najširšieho pixelov 4:1 až najvyššieho pixelov1:4 v porovnaní s 1/64.Hodnoty :0 - Informácie o pomere aspektov sa neposkytujú.1..255 - hodnota použitá pri výpočte.