public class GifOptions extends ImageOptionsBase
The gif file format creation options.
This example demonstrates the use of different classes from SaveOptions Namespace for export purposes. An image of type Gif is loaded into an instance of Image and then exported out to several formats.
String dir = "c:\\temp\\"; //Load an existing image (of type Gif) in an instance of Image class com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.gif"); try { //Export to BMP file format using the default options image.save(dir + "output.bmp", new com.aspose.imaging.imageoptions.BmpOptions()); //Export to JPEG file format using the default options image.save(dir + "output.jpeg", new com.aspose.imaging.imageoptions.JpegOptions()); //Export to PNG file format using the default options image.save(dir + "output.png", new com.aspose.imaging.imageoptions.PngOptions()); //Export to TIFF file format using the default options image.save(dir + "output.tif", new com.aspose.imaging.imageoptions.TiffOptions(com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat.Default)); } finally { image.dispose(); }
Constructor and Description |
---|
GifOptions()
Initializes a new instance of the
GifOptions class. |
GifOptions(GifOptions gifOptions)
Initializes a new instance of the
GifOptions class. |
Modifier and Type | Method and Description |
---|---|
byte |
getBackgroundColorIndex()
Gets or sets the GIF background color index.
|
byte |
getColorResolution()
Gets or sets the GIF color resolution.
|
boolean |
getDoPaletteCorrection()
Gets or sets a value indicating whether palette correction is applied.
|
boolean |
getInterlaced()
True if image should be interlaced.
|
int |
getMaxDiff()
Gets or sets the maximum allowed pixel difference.
|
byte |
getPixelAspectRatio()
Gets or sets the GIF pixel aspect ratio.
|
XmpPacketWrapper |
getXmpData()
Gets or sets the XMP metadata container.
|
boolean |
hasTrailer()
Gets or sets a value indicating whether GIF has trailer.
|
boolean |
isPaletteSorted()
Gets or sets a value indicating whether palette entries are sorted.
|
void |
setBackgroundColorIndex(byte value)
Gets or sets the GIF background color index.
|
void |
setColorResolution(byte value)
Gets or sets the GIF color resolution.
|
void |
setDoPaletteCorrection(boolean value)
Gets or sets a value indicating whether palette correction is applied.
|
void |
setInterlaced(boolean value)
True if image should be interlaced.
|
void |
setMaxDiff(int value)
Gets or sets the maximum allowed pixel difference.
|
void |
setPaletteSorted(boolean value)
Gets or sets a value indicating whether palette entries are sorted.
|
void |
setPixelAspectRatio(byte value)
Gets or sets the GIF pixel aspect ratio.
|
void |
setTrailer(boolean value)
Gets or sets a value indicating whether GIF has trailer.
|
void |
setXmpData(XmpPacketWrapper value)
Gets or sets the XMP metadata container.
|
deepClone, getBufferSizeHint, getMultiPageOptions, getPalette, getProgressEventHandler, getResolutionSettings, getSource, getVectorRasterizationOptions, setBufferSizeHint, setMultiPageOptions, setPalette, setProgressEventHandler, setResolutionSettings, setSource, setVectorRasterizationOptions
close, dispose, getDisposed
public GifOptions()
Initializes a new instance of the GifOptions
class.
public GifOptions(GifOptions gifOptions)
Initializes a new instance of the GifOptions
class.
gifOptions
- The GIF Options.public XmpPacketWrapper getXmpData()
Gets or sets the XMP metadata container.
getXmpData
in class ImageOptionsBase
public void setXmpData(XmpPacketWrapper value)
Gets or sets the XMP metadata container.
setXmpData
in class ImageOptionsBase
value
- The XMP data container.public boolean getDoPaletteCorrection()
Gets or sets a value indicating whether palette correction is applied.
true
if palette correction is applied; otherwise, false
.
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). The analyze process takes some time however the output image will have the best matching color palette and result is visually better.
public void setDoPaletteCorrection(boolean value)
Gets or sets a value indicating whether palette correction is applied.
value
- true
if palette correction is applied; otherwise, false
.
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). The analyze process takes some time however the output image will have the best matching color palette and result is visually better.
This example shows how to save a BMP image to GIF format using various options.
String dir = "c:\\temp\\"; com.aspose.imaging.Image bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(1000, 1000); try { // Fill the entire image with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(bmpImage.getWidth(), bmpImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(bmpImage); graphics.fillRectangle(gradientBrush, bmpImage.getBounds()); com.aspose.imaging.imageoptions.GifOptions saveOptions = new com.aspose.imaging.imageoptions.GifOptions(); // The number of bits required to store a color, minus 1. saveOptions.setColorResolution((byte) 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.setDoPaletteCorrection(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.setInterlaced(true); // Save as a lossless GIF. java.io.FileOutputStream stream = new java.io.FileOutputStream(dir + "output.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossless GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } // 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.setMaxDiff(80); // Save as a lossy GIF. stream = new java.io.FileOutputStream(dir + "output.lossy.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossy GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } } finally { bmpImage.close(); } //The output may look like this: //The size of the lossless GIF: 212816 bytes. //The size of the lossy GIF: 89726 bytes.
public byte getColorResolution()
Gets or sets the GIF color resolution.
Color Resolution - Number of bits per primary color available to the original image, minus 1. This value represents the size of the entire palette from which the colors in the graphic were selected, not the number of colors actually used in the graphic. For example, if the value in this field is 3, then the palette of the original image had 4 bits per primary color available to create the image. This value should be set to indicate the richness of the original palette, even if not every color from the whole palette is available on the source machine.
public void setColorResolution(byte value)
Gets or sets the GIF color resolution.
value
- The color resolution.
Color Resolution - Number of bits per primary color available to the original image, minus 1. This value represents the size of the entire palette from which the colors in the graphic were selected, not the number of colors actually used in the graphic. For example, if the value in this field is 3, then the palette of the original image had 4 bits per primary color available to create the image. This value should be set to indicate the richness of the original palette, even if not every color from the whole palette is available on the source machine.
This example shows how to save a BMP image to GIF format using various options.
String dir = "c:\\temp\\"; com.aspose.imaging.Image bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(1000, 1000); try { // Fill the entire image with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(bmpImage.getWidth(), bmpImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(bmpImage); graphics.fillRectangle(gradientBrush, bmpImage.getBounds()); com.aspose.imaging.imageoptions.GifOptions saveOptions = new com.aspose.imaging.imageoptions.GifOptions(); // The number of bits required to store a color, minus 1. saveOptions.setColorResolution((byte) 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.setDoPaletteCorrection(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.setInterlaced(true); // Save as a lossless GIF. java.io.FileOutputStream stream = new java.io.FileOutputStream(dir + "output.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossless GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } // 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.setMaxDiff(80); // Save as a lossy GIF. stream = new java.io.FileOutputStream(dir + "output.lossy.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossy GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } } finally { bmpImage.close(); } //The output may look like this: //The size of the lossless GIF: 212816 bytes. //The size of the lossy GIF: 89726 bytes.
public boolean isPaletteSorted()
Gets or sets a value indicating whether palette entries are sorted.
true
if palette entries are sorted; otherwise, false
.public void setPaletteSorted(boolean value)
Gets or sets a value indicating whether palette entries are sorted.
value
- true
if palette entries are sorted; otherwise, false
.public byte getPixelAspectRatio()
Gets or sets the GIF pixel aspect ratio.
Pixel Aspect Ratio - Factor used to compute an approximation of the aspect ratio of the pixel in the original image. If the value of the field is not 0, this approximation of the aspect ratio is computed based on the formula: Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 The Pixel Aspect Ratio is defined to be the quotient of the pixel's width over its height. The value range in this field allows specification of the widest pixel of 4:1 to the tallest pixel of 1:4 in increments of 1/64th. Values : 0 - No aspect ratio information is given. 1..255 - Value used in the computation.
public void setPixelAspectRatio(byte value)
Gets or sets the GIF pixel aspect ratio.
Pixel Aspect Ratio - Factor used to compute an approximation of the aspect ratio of the pixel in the original image. If the value of the field is not 0, this approximation of the aspect ratio is computed based on the formula: Aspect Ratio = (Pixel Aspect Ratio + 15) / 64 The Pixel Aspect Ratio is defined to be the quotient of the pixel's width over its height. The value range in this field allows specification of the widest pixel of 4:1 to the tallest pixel of 1:4 in increments of 1/64th. Values : 0 - No aspect ratio information is given. 1..255 - Value used in the computation.
value
- The GIF pixel aspect ratio.public byte getBackgroundColorIndex()
Gets or sets the GIF background color index.
public void setBackgroundColorIndex(byte value)
Gets or sets the GIF background color index.
value
- The GIF background color index.public boolean hasTrailer()
Gets or sets a value indicating whether GIF has trailer.
true
if GIF has trailer; otherwise, false
.public void setTrailer(boolean value)
Gets or sets a value indicating whether GIF has trailer.
value
- true
if GIF has trailer; otherwise, false
.public boolean getInterlaced()
True if image should be interlaced.
public void setInterlaced(boolean value)
True if image should be interlaced.
This example shows how to save a BMP image to GIF format using various options.
String dir = "c:\\temp\\"; com.aspose.imaging.Image bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(1000, 1000); try { // Fill the entire image with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(bmpImage.getWidth(), bmpImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(bmpImage); graphics.fillRectangle(gradientBrush, bmpImage.getBounds()); com.aspose.imaging.imageoptions.GifOptions saveOptions = new com.aspose.imaging.imageoptions.GifOptions(); // The number of bits required to store a color, minus 1. saveOptions.setColorResolution((byte) 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.setDoPaletteCorrection(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.setInterlaced(true); // Save as a lossless GIF. java.io.FileOutputStream stream = new java.io.FileOutputStream(dir + "output.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossless GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } // 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.setMaxDiff(80); // Save as a lossy GIF. stream = new java.io.FileOutputStream(dir + "output.lossy.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossy GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } } finally { bmpImage.close(); } //The output may look like this: //The size of the lossless GIF: 212816 bytes. //The size of the lossy GIF: 89726 bytes.
public int getMaxDiff()
Gets or sets the maximum allowed pixel difference. If greater than zero, lossy compression will be used. Recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy. It works best when only little loss is introduced, and due to limitation of the compression algorithm very high loss levels won't give as much gain. The range of allowed values is [0, 1000].
public void setMaxDiff(int value)
Gets or sets the maximum allowed pixel difference. If greater than zero, lossy compression will be used. Recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy. It works best when only little loss is introduced, and due to limitation of the compression algorithm very high loss levels won't give as much gain. The range of allowed values is [0, 1000].
value
- The range of allowed values.This example shows how to save a BMP image to GIF format using various options.
String dir = "c:\\temp\\"; com.aspose.imaging.Image bmpImage = new com.aspose.imaging.fileformats.bmp.BmpImage(1000, 1000); try { // Fill the entire image with the blue-yellow gradient. com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(bmpImage.getWidth(), bmpImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getYellow()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(bmpImage); graphics.fillRectangle(gradientBrush, bmpImage.getBounds()); com.aspose.imaging.imageoptions.GifOptions saveOptions = new com.aspose.imaging.imageoptions.GifOptions(); // The number of bits required to store a color, minus 1. saveOptions.setColorResolution((byte) 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.setDoPaletteCorrection(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.setInterlaced(true); // Save as a lossless GIF. java.io.FileOutputStream stream = new java.io.FileOutputStream(dir + "output.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossless GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } // 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.setMaxDiff(80); // Save as a lossy GIF. stream = new java.io.FileOutputStream(dir + "output.lossy.gif"); try { bmpImage.save(stream, saveOptions); System.out.printf("The size of the lossy GIF: %s bytes.\r\n", stream.getChannel().size()); } finally { stream.close(); } } finally { bmpImage.close(); } //The output may look like this: //The size of the lossless GIF: 212816 bytes. //The size of the lossy GIF: 89726 bytes.