Class GifOptions
Названий на: Aspose.Imaging.ImageOptions Асамблея: Aspose.Imaging.dll (25.4.0)
API для графічного формату обміну (GIF) raster image file creation пропонуєрозробники всеосяжні варіанти для генерування 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 завантажується в інстанцію Image і потім експортується до декількох форматів.
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));
}
Наступний приклад показує, як конвертувати багатосторонню вікторну картину в форматі 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 в Array of Type Color, маніпулює array і повертає її до зображення. Для виконання цих операцій цей примір створює новий файл Image (в форматі 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.GifOption.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Ініціалізація нової інстанції класу Aspose.Imaging.ImageOptions.GifOption.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
Вибір варіантів GIF.
Properties
BackgroundColor
Приймати або встановити колір фону.
[JsonProperty]
public Color BackgroundColor { get; set; }
вартість нерухомості
BackgroundColorIndex
Отримати або встановити індекс кольору фону GIF.
public byte BackgroundColorIndex { get; set; }
вартість нерухомості
ColorResolution
Знайдіть або встановити кольорову резолюцію GIF.
public byte ColorResolution { get; set; }
вартість нерухомості
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
Резолюція кольорів - кількість бітів за первинним кольоромдо оригінального зображення, минус 1.Ця вартість являє собою розмірцілий палет, з якого кольори в графіці булиВибрано, не кількість кольорів, які фактично використовуються в графіці.Наприклад, якщо значення в цьому полі становить 3, то палетОригінальний зображення мав 4 біти за первинний колір, доступний для створенняЦя вартість повинна бути встановлена для того, щоб вказувати на багатствооригінальна палетка, навіть якщо не всі кольори в ціломуПалет доступний на джереловій машині.
DoPaletteCorrection
Приймає або встановлює значення, яке вказує на те, чи застосовується палетна корекція.
public bool DoPaletteCorrection { get; set; }
вартість нерухомості
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; }
вартість нерухомості
HasTransparentColor
Отримає або встановлює значення, яке вказує на те, чи має зображення GIF прозорий колір.Якщо вартість повернення нуль, ця власність перебільшується джерельним зображенням контексту.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
вартість нерухомості
bool ?
Interlaced
Правда, якщо зображення має бути взаємопов’язане.
public bool Interlaced { get; set; }
вартість нерухомості
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; }
вартість нерухомості
LoopsCount
Знайти або встановити кількість лопів (за замовчуванням 1 лоп)
public int LoopsCount { get; set; }
вартість нерухомості
MaxDiff
Приймає або встановлює максимальний дозволений розрив пікселів. якщо він перевищує нуль, використовується компресія втрат.Рекомендована вартість для оптимальної компресії втрати 80 - 30 - дуже легка компресія, 200 - важка.Найкраще працює, коли вводиться лише невелика втрата, і через обмеження алгоритму компресії дуже високі рівні втрат не дадуть такої великої прибутку.Обсяг дозволених значень [0, 1000].
public int MaxDiff { get; set; }
вартість нерухомості
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; }
вартість нерухомості
Remarks
Pixel Aspect Ratio — фактор, що використовується для обчислення приблизностівід відношення аспекту пікселя в оригінальному зображенні.значення поля не 0, це приближення відношення аспектуРозрахунок здійснюється за формулою:Aspect Ratio = (Pixel Aspect Ratio + 15) / 64Рівень аспекту пікселів визначається як коефіцієнт пікселів.широта над його висотою. вартість діапазону в цьому полі дозволяєРозмір пікселя 4:1 до найвищого пікселя1:4 у збільшеннях 1/64цінності :0 - Не надається інформація про відношення аспектів.1..255 - Вартість, що використовується для обчислення.