Class GifOptions
نام ها : Aspose.Imaging.ImageOptions جمع آوری: Aspose.Imaging.dll (25.4.0)
API for Graphical Interchange Format (GIF) ایجاد فایل تصویر راستر ارائه می دهدتوسعه دهندگان گزینه های جامع برای تولید تصاویر 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 به یک مثال از تصویر بارگذاری می شود و سپس به فرمت های مختلف صادر می شود.
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);
}
این مثال نشان می دهد که چگونه اطلاعات پیکسل را در یک ردیف نوع رنگ بارگذاری کنید، ردیف را دستکاری کنید و آن را به تصویر بازگردانید.برای انجام این عملیات، این مثال یک فایل تصویر جدید (در فرمت GIF) ایجاد می کند.
//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.GifOptions.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
شروع یک مثال جدید از کلاس Aspose.Imaging.ImageOptions.GifOptions.
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
رزولوشن رنگی - تعداد بیت ها در هر رنگ اصلی در دسترس استبه تصویر اصلی، minus 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) / 64Pixel Aspect Ratio به عنوان مقدار پیکسل شناخته می شود.محدوده ارزش در این زمینه اجازه می دهد تامشخصات گسترده ترین پیکسل از 4:1 به بالاترین پیکسل از1:4 در افزایش 1/64th.ارزش ها :0 - هیچ اطلاعات نسبت جنبه ای ارائه نمی شود.1 .255 - ارزش مورد استفاده در محاسبه.