public class PngOptions extends ImageOptionsBase
The png file format create 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 |
---|
PngOptions()
Initializes a new instance of the
PngOptions class. |
PngOptions(PngOptions pngOptions)
Initializes a new instance of the
JpegOptions class. |
Modifier and Type | Method and Description |
---|---|
byte |
getBitDepth()
Gets the bit depth.
|
int |
getColorType()
Gets or sets the type of the color.
|
int |
getCompressionLevel()
The png image compression level in the 0-9 range, where 9 is maximum compression and 0 is store mode.
|
int |
getFilterType()
Gets or sets the filter type used during png file save process.
|
boolean |
getProgressive()
Gets or sets a value indicating whether this
PngOptions is progressive. |
XmpPacketWrapper |
getXmpData()
Gets or sets the XMP metadata container.
|
void |
setBitDepth(byte value)
Sets the bit depth.
|
void |
setColorType(int value)
Gets or sets the type of the color.
|
void |
setCompressionLevel(int value)
The png image compression level in the 0-9 range, where 9 is maximum compression and 0 is store mode.
|
void |
setFilterType(int value)
Gets or sets the filter type used during png file save process.
|
void |
setProgressive(boolean value)
Gets or sets a value indicating whether this
PngOptions is progressive. |
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 PngOptions()
Initializes a new instance of the PngOptions
class.
public PngOptions(PngOptions pngOptions)
Initializes a new instance of the JpegOptions
class.
pngOptions
- The PNG options.public XmpPacketWrapper getXmpData()
Gets or sets the XMP metadata container.
Value: The XMP data container.getXmpData
in class ImageOptionsBase
public void setXmpData(XmpPacketWrapper value)
Gets or sets the XMP metadata container.
Value: The XMP data container.setXmpData
in class ImageOptionsBase
value
- The XMP data container.public int getColorType()
Gets or sets the type of the color.
PngColorType
public void setColorType(int value)
Gets or sets the type of the color.
value
- The type of the color.PngColorType
The following example shows how to save an image to PNG format using various options.
String dir = "c:\\temp\\"; // Create a PNG image of 100x100 px. // You can also load image of any supported format from a file or a stream. com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(100, 100); try { com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(pngImage.getWidth(), pngImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getTransparent()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage); // Fill the image with the blue-transparent gradient. graphics.fillRectangle(gradientBrush, pngImage.getBounds()); com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions(); // Use progressive loading. saveOptions.setProgressive(true); // Set the horizontal and vertical resolution to 96 pixels per inch. saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0)); // Each pixel is a (red, green, blue) triple followed by alpha. saveOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha); // Set the maximum level of compression. saveOptions.setCompressionLevel(9); // This is the best compression, but the slowest execution time. // Adaptive filtering means that saving process will choose most sutable filter for each data row. saveOptions.setFilterType(com.aspose.imaging.fileformats.png.PngFilterType.Adaptive); // The number of bits per channel. saveOptions.setBitDepth((byte) 8); // Save to a file. pngImage.save(dir + "output.png", saveOptions); } finally { pngImage.dispose(); }
public boolean getProgressive()
Gets or sets a value indicating whether this PngOptions
is progressive.
true
if progressive; otherwise, false
.public void setProgressive(boolean value)
Gets or sets a value indicating whether this PngOptions
is progressive.
value
- true
if progressive; otherwise, false
.This example shows how to create a PNG image with the specified options, fill it with a linear gradient colors and save it to a file.
String dir = "c:\\temp\\"; com.aspose.imaging.imageoptions.PngOptions createOptions = new com.aspose.imaging.imageoptions.PngOptions(); // The number of bits per color channel createOptions.setBitDepth((byte) 8); // Each pixel is a (red, green, blue) triple followed by the alpha component. createOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha); // The maximum level of compression. createOptions.setCompressionLevel(9); // Usage of filters allows to compress continuous tonal images more effectively. createOptions.setFilterType(com.aspose.imaging.fileformats.png.PngFilterType.Sub); // Use progressive loading createOptions.setProgressive(true); // Create a PNG image with custom parameters. com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(createOptions, 100, 100); try { com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(pngImage.getWidth(), pngImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getTransparent()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage); // Fill the image with a semi-transparent gradient. graphics.fillRectangle(gradientBrush, pngImage.getBounds()); // Save to a file. pngImage.save(dir + "output.explicitoptions.png"); } finally { pngImage.dispose(); }
public int getFilterType()
Gets or sets the filter type used during png file save process.
PngFilterType
public void setFilterType(int value)
Gets or sets the filter type used during png file save process.
value
- the filter type used during png file save process.PngFilterType
The following example shows how different filter types affect the size of the output PNG image.
// Helper class class Utils { public String getPngFilterTypeString(int filterType) { switch (filterType) { case com.aspose.imaging.fileformats.png.PngFilterType.None: return "None"; case com.aspose.imaging.fileformats.png.PngFilterType.Up: return "Up"; case com.aspose.imaging.fileformats.png.PngFilterType.Sub: return "Sub"; case com.aspose.imaging.fileformats.png.PngFilterType.Paeth: return "Paeth"; case com.aspose.imaging.fileformats.png.PngFilterType.Avg: return "Avg"; case com.aspose.imaging.fileformats.png.PngFilterType.Adaptive: return "Adaptive"; default: throw new IllegalArgumentException("filterType"); } } } // Here is the main example Utils utils = new Utils(); int[] filterTypes = new int[] { com.aspose.imaging.fileformats.png.PngFilterType.None, com.aspose.imaging.fileformats.png.PngFilterType.Up, com.aspose.imaging.fileformats.png.PngFilterType.Sub, com.aspose.imaging.fileformats.png.PngFilterType.Paeth, com.aspose.imaging.fileformats.png.PngFilterType.Avg, com.aspose.imaging.fileformats.png.PngFilterType.Adaptive, }; for (int filterType : filterTypes) { com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions(); com.aspose.imaging.Image image = com.aspose.imaging.Image.load("c:\\temp\\sample.png"); try { // Set a filter type options.setFilterType(filterType); java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream(); try { image.save(stream, options); System.out.printf("The filter type is %s, the output image size is %s bytes.", utils.getPngFilterTypeString(filterType), stream.size()); } finally { stream.close(); } } finally { image.dispose(); } } //The output may look like this: //The filter type is None, the output image size is 116845 bytes. //The filter type is Up, the output image size is 86360 bytes. //The filter type is Sub, the output image size is 94907 bytes. //The filter type is Paeth, the output image size is 86403 bytes. //The filter type is Avg, the output image size is 89956 bytes. //The filter type is Adaptive, the output image size is 97248 bytes.
public int getCompressionLevel()
The png image compression level in the 0-9 range, where 9 is maximum compression and 0 is store mode.
public void setCompressionLevel(int value)
The png image compression level in the 0-9 range, where 9 is maximum compression and 0 is store mode.
value
- the compression level in the 0-9 range, where 9 is maximum compression and 0 is store mode.The following example shows how to save an image to PNG format using various options.
String dir = "c:\\temp\\"; // Create a PNG image of 100x100 px. // You can also load image of any supported format from a file or a stream. com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(100, 100); try { com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(pngImage.getWidth(), pngImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getTransparent()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage); // Fill the image with the blue-transparent gradient. graphics.fillRectangle(gradientBrush, pngImage.getBounds()); com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions(); // Use progressive loading. saveOptions.setProgressive(true); // Set the horizontal and vertical resolution to 96 pixels per inch. saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0)); // Each pixel is a (red, green, blue) triple followed by alpha. saveOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha); // Set the maximum level of compression. saveOptions.setCompressionLevel(9); // This is the best compression, but the slowest execution time. // Adaptive filtering means that saving process will choose most sutable filter for each data row. saveOptions.setFilterType(com.aspose.imaging.fileformats.png.PngFilterType.Adaptive); // The number of bits per channel. saveOptions.setBitDepth((byte) 8); // Save to a file. pngImage.save(dir + "output.png", saveOptions); } finally { pngImage.dispose(); }
public byte getBitDepth()
Gets the bit depth.
public void setBitDepth(byte value)
Sets the bit depth.
value
- The bit depth.The following example shows how to save an image to PNG format using various options.
String dir = "c:\\temp\\"; // Create a PNG image of 100x100 px. // You can also load image of any supported format from a file or a stream. com.aspose.imaging.fileformats.png.PngImage pngImage = new com.aspose.imaging.fileformats.png.PngImage(100, 100); try { com.aspose.imaging.brushes.LinearGradientBrush gradientBrush = new com.aspose.imaging.brushes.LinearGradientBrush( new com.aspose.imaging.Point(0, 0), new com.aspose.imaging.Point(pngImage.getWidth(), pngImage.getHeight()), com.aspose.imaging.Color.getBlue(), com.aspose.imaging.Color.getTransparent()); com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(pngImage); // Fill the image with the blue-transparent gradient. graphics.fillRectangle(gradientBrush, pngImage.getBounds()); com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions(); // Use progressive loading. saveOptions.setProgressive(true); // Set the horizontal and vertical resolution to 96 pixels per inch. saveOptions.setResolutionSettings(new com.aspose.imaging.ResolutionSetting(96.0, 96.0)); // Each pixel is a (red, green, blue) triple followed by alpha. saveOptions.setColorType(com.aspose.imaging.fileformats.png.PngColorType.TruecolorWithAlpha); // Set the maximum level of compression. saveOptions.setCompressionLevel(9); // This is the best compression, but the slowest execution time. // Adaptive filtering means that saving process will choose most sutable filter for each data row. saveOptions.setFilterType(com.aspose.imaging.fileformats.png.PngFilterType.Adaptive); // The number of bits per channel. saveOptions.setBitDepth((byte) 8); // Save to a file. pngImage.save(dir + "output.png", saveOptions); } finally { pngImage.dispose(); }