Class GifOptions
ja nimityö: Aspose.Imaging.ImageOptions Kokoelma: Aspose.Imaging.dll (25.4.0)
API Graphical Interchange Format (GIF) raster kuvan tiedoston luominen tarjoaakehittäjät kattavat mahdollisuudet tuottaa GIF-kuvia tarkastivalvonta. ominaisuuksia asettaa taustaväri, väri paletti, resoluutio,sidottu tyyppi, läpinäkyvä väri, XMP-metatietokanta ja kuvakompression, tämä API takaa joustavuutta ja tehokkuutta luoda optimoituja visuaalisesti houkuttelevat GIF:t, jotka on räätälöity erityisiin sovellusvaatimuksiin.
[JsonObject(MemberSerialization.OptIn)]
public class GifOptions : ImageOptionsBase, IDisposable, IHasXmpData, IHasMetadata, ICloneable
Inheritance
object ← DisposableObject ← ImageOptionsBase ← GifOptions
Implements
IDisposable , IHasXmpData , IHasMetadata , ICloneable
Perintöjäsenet
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
Tämä esimerkki osoittaa eri luokkien käytön SaveOptions Namespace vientiä varten. Gif-tyypin kuva ladataan kuvan tapaukseen ja sitten viedään useisiin muotoihin.
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));
}
Seuraava esimerkki näyttää, miten muuntaa monipuolinen vektorikuva GIF-muodossa yleensä viittaamatta tiettyyn kuvan tyyppiin.
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);
}
Tämä esimerkki näyttää, miten Lataa Pixel-tietoja tyypin värijärjestelmässä, manipuloi järjestelmää ja asettaa sen takaisin kuviin. Näiden toimintojen suorittamiseksi tämä esimerki luo uuden kuvan tiedoston (GIF-muodossa) uisng MemoryStream-objekti.
//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()
Aloita uusi esimerkki Aspose.Imaging.ImageOptions.GifOption luokan.
[JsonConstructor]
public GifOptions()
GifOptions(GifOptions)
Aloita uusi esimerkki Aspose.Imaging.ImageOptions.GifOption luokan.
public GifOptions(GifOptions gifOptions)
Parameters
gifOptions
GifOptions
GIF vaihtoehtoja varten.
Properties
BackgroundColor
Antaa tai asettaa taustaväri.
[JsonProperty]
public Color BackgroundColor { get; set; }
Omistuksen arvo
BackgroundColorIndex
Antaa tai asettaa GIF taustan värin indeksi.
public byte BackgroundColorIndex { get; set; }
Omistuksen arvo
ColorResolution
Saa tai asettaa GIF-värin resoluution.
public byte ColorResolution { get; set; }
Omistuksen arvo
Examples
Tämä esimerkki näyttää, miten tallentaa BMP-kuva GIF-muodossa käyttämällä erilaisia vaihtoehtoja.
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
Väri Resoluutio - Käytettävissä olevien bittien lukumäärä per päävärialkuperäisen kuvan, minus 1. Tämä arvo edustaakoko paletti, josta värit grafiikassa olivatvalittu, ei värien lukumäärä, jota grafiikassa käytetään.Esimerkiksi, jos tämän kentän arvo on 3, niin palettiAlkuperäinen kuva oli 4 bitia per alkuperäinen väri käytettävissä luodaTämä arvo on asetettava osoittamaan rikkaudenalkuperäinen paletti, vaikka ei jokainen väri kokoPaletti on saatavilla lähteen koneella.
DoPaletteCorrection
Saat tai asetat arvon, joka osoittaa, sovelletaanko paletin korjausta.
public bool DoPaletteCorrection { get; set; }
Omistuksen arvo
Examples
Tämä esimerkki näyttää, miten tallentaa BMP-kuva GIF-muodossa käyttämällä erilaisia vaihtoehtoja.
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
Paletin korjaus tarkoittaa, että joka kerta, kun kuvaa viedään GIF:een, lähdekuvan värit analysoidaan.luodaan paras vastaava paletti (jossa kuvapaletti ei ole olemassa tai ei ole määritelty vaihtoehdoissa).Analyysin prosessi vie jonkin aikaa, mutta tuloskuva on paras vastaava väri paletti ja tulos on visuaalisesti parempi.
HasTrailer
Saat tai asetat arvon, joka osoittaa, onko GIF:llä traileri.
public bool HasTrailer { get; set; }
Omistuksen arvo
HasTransparentColor
Saa tai asettaa arvo, joka osoittaa, onko GIF-kuvassa läpinäkyvä väri.Jos palautusarvo on nollan, tämä omaisuus on ylitetty lähdekuvan konteksti.
[JsonProperty]
public bool? HasTransparentColor { get; set; }
Omistuksen arvo
bool ?
Interlaced
Se on totta, jos kuvaa tulisi yhdistää.
public bool Interlaced { get; set; }
Omistuksen arvo
Examples
Tämä esimerkki näyttää, miten tallentaa BMP-kuva GIF-muodossa käyttämällä erilaisia vaihtoehtoja.
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
Saat tai asetat arvon, joka osoittaa, onko paletin tulokset lajitelty.
public bool IsPaletteSorted { get; set; }
Omistuksen arvo
LoopsCount
Saa tai asettaa looppien lukumäärän (Default 1 loop)
public int LoopsCount { get; set; }
Omistuksen arvo
MaxDiff
Saat tai asettaa maksimaalisen sallitun pikselin eron. Jos se on suurempi kuin nolla, käytetään tappiota.Suositeltu arvo optimaaliselle tappiotekompressiolle on 80. 30 on erittäin kevyt kompressi, 200 on raskas.Se toimii parhaiten, kun vain pieni menetys otetaan käyttöön, ja tiivistyksen algoritmin rajoittamisen vuoksi erittäin korkea menetysaste ei anna niin paljon voittoa.Määrä sallittujen arvojen välillä on [0, 1000].
public int MaxDiff { get; set; }
Omistuksen arvo
Examples
Tämä esimerkki näyttää, miten tallentaa BMP-kuva GIF-muodossa käyttämällä erilaisia vaihtoehtoja.
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
Saa tai asettaa GIF-pikselin näkökulman suhteen.
public byte PixelAspectRatio { get; set; }
Omistuksen arvo
Remarks
Pixel Aspect Ratio - tekijä, jota käytetään lähentymisen laskemiseenPikselin näkösuunta alkuperäisessä kuvassa.kentän arvo ei ole 0, tämä näkökohdan suhteen lähentyminenSe lasketaan kaavan perusteella:Aspect Ratio = (Pixel Aspect Ratio + 15) / 64Pixel Aspect Ratio on määritelty pixelin suhteeksi.laajuus sen korkeuden yläpuolella. arvoalue tässä kentässä mahdollistaaMääritelmä laajimmasta pikseliä 4:1 korkeimpaan pikseliin1:4 ja 1 / 64:n lisät.Arvot ovat:0 - Tietoa ei ole annettu näkökohdan suhteen.1..255 - Laskennassa käytetty arvo.