Class PngImage
- Namespace
- Aspose.Imaging.FileFormats.Png
- Assembly
- Aspose.Imaging.dll
Manipulate Portable Network Graphics (PNG) raster images with our versatile API, featuring support for compression levels and various color depths including Grayscale, Indexed Color, TrueColor, and alpha channels. Seamlessly process XMP metadata, enabling comprehensive image metadata management, while easily loading PNG images, performing diverse manipulations, applying filters, and converting images to other file formats for optimal versatility and customization.
public class PngImage : RasterCachedImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata
- Inheritance
-
PngImage
- Implements
- Inherited Members
Constructors
PngImage(PngOptions, int, int)
Initialize a new instance of the PngImage class, incorporating PNG options alongside width and height parameters. This constructor empowers developers to create PNG images with customizable settings and dimensions, offering flexibility in image generation for diverse use cases.
public PngImage(PngOptions pngOptions, int width, int height)
Parameters
pngOptions
PngOptionsThe png options.
width
intThe width.
height
intThe height.
PngImage(RasterImage)
Creates a new instance of the PngImage class by providing a raster image as a parameter. This constructor allows developers to directly initialize a PNG image object using an existing raster image, streamlining the process of working with PNG images in their applications.
public PngImage(RasterImage rasterImage)
Parameters
rasterImage
RasterImageThe raster image.
PngImage(RasterImage, PngColorType)
Creates a new instance of the PngImage class by specifying a raster image and a color type. This constructor enables developers to directly convert raster images into PNG format while specifying the desired color type, offering flexibility in color representation.
public PngImage(RasterImage rasterImage, PngColorType colorType)
Parameters
rasterImage
RasterImageThe raster image.
colorType
PngColorTypeThe color type.
PngImage(Stream)
Creates a new instance of the PngImage class by initializing it with a stream. This constructor allows developers to load PNG images directly from a stream, providing flexibility in image retrieval from different sources.
public PngImage(Stream stream)
Parameters
stream
StreamThe stream to load an image.
PngImage(int, int)
Initialize a new object of the PngImage class by providing the width and height parameters. This constructor simplifies the creation of PNG images by allowing developers to specify the dimensions directly, facilitating efficient management of PNG image data within their applications.
public PngImage(int width, int height)
Parameters
PngImage(int, int, PngColorType)
Instantiate a fresh instance of the PngImage class, specifying the desired width, height, and color type parameters. This constructor enables swift creation of PNG images with tailored dimensions and color configurations, facilitating streamlined image generation for various applications and workflows.
public PngImage(int width, int height, PngColorType colorType)
Parameters
width
intThe width.
height
intThe height.
colorType
PngColorTypeThe color type.
PngImage(string)
Constructs a new instance of the PngImage class using the path parameter to specify the location of the image file to load. This constructor enables developers to conveniently create PNG images by loading them from a file, simplifying the process of working with PNG images in their applications.
public PngImage(string path)
Parameters
path
stringThe path to load an image.
PngImage(string, PngColorType)
Initializes a new instance of the PngImage class by specifying the path to the image file and the color type. This constructor allows for convenient creation of PNG images from files with different color types, providing flexibility in handling various image formats.
public PngImage(string path, PngColorType colorType)
Parameters
path
stringThe path to load an image.
colorType
PngColorTypeThe color type.
Exceptions
Properties
BackgroundColor
Retrieves the background color of the image, if one is specified. This property is helpful for applications that need to identify and potentially manipulate the background color of an image.
public override Color BackgroundColor { get; set; }
Property Value
BitsPerPixel
Retrieve the bits per pixel value for the image. This property provides crucial information regarding the color depth of the image, enabling developers to understand the level of detail and color accuracy present in the image data.
public override int BitsPerPixel { get; }
Property Value
FileFormat
Retrieves the format of the file associated with the image instance. This property provides essential information regarding the file type, enabling efficient handling and processing based on the specific format requirements.
public override FileFormat FileFormat { get; }
Property Value
HasAlpha
Returns a boolean value indicating whether the image has an alpha channel, which determines its transparency. This property is useful for applications that need to handle transparency, allowing developers to determine whether additional processing is required to handle transparent areas in the image.
public override bool HasAlpha { get; }
Property Value
- bool
true
if this instance has alpha; otherwise,false
.
HasBackgroundColor
Retrieves a boolean value indicating whether the image has a background color. This property is useful for applications needing to determine if an image includes a background color, which can be important for various processing tasks such as compositing, rendering, or exporting.
public override bool HasBackgroundColor { get; set; }
Property Value
HasTransparentColor
Provides a boolean value indicating whether the image contains a transparent color. This property is crucial for applications that need to handle transparency, allowing developers to determine whether additional processing is required to handle transparent regions in the image.
public override bool HasTransparentColor { get; set; }
Property Value
Height
Obtain the height of the image. This property returns the vertical dimension of the image, allowing developers to determine its size in pixels along the vertical axis.
public override int Height { get; }
Property Value
HorizontalResolution
Retrieve or modify the horizontal resolution of the image. This property represents the number of pixels per inch along the horizontal axis of the image. Adjusting this resolution can affect the physical size of the image when printed or displayed.
public override double HorizontalResolution { get; set; }
Property Value
Interlaced
Retrieves a boolean value indicating whether the PngImage is interlaced, which determines if the image data is stored in a progressive manner for faster loading or transmission.
public bool Interlaced { get; }
Property Value
- bool
true
if interlaced; otherwise,false
.
IsInterlaced
Returns a boolean value indicating if the image instance is interlaced. This property is crucial for optimizing loading strategies and ensuring efficient performance during image processing or display tasks.
public bool IsInterlaced { get; }
Property Value
- bool
true
if this image instance is interlaced; otherwise,false
.
RawDataFormat
Accesses the raw data format of the image. This property provides insight into how the image data is structured internally, which can be useful for advanced image processing tasks or format conversion.
public override PixelDataFormat RawDataFormat { get; }
Property Value
TransparentColor
Retrieves the transparent color of the image, if it exists. This property is valuable for applications requiring precise handling of transparent areas within images, allowing developers to access and manipulate the specific transparent color used.
public override Color TransparentColor { get; set; }
Property Value
VerticalResolution
Provides access to the vertical resolution of the image. Developers can use this property to retrieve or modify the resolution setting, which indicates the number of pixels per inch (PPI) along the vertical axis of the image.
public override double VerticalResolution { get; set; }
Property Value
Width
Allows retrieval of the width of the image, providing essential information about its dimensions. This property is frequently used by developers to determine the image's width, enabling them to perform various operations based on its size
public override int Width { get; }
Property Value
XmpData
Accesses or modifies the Extensible Metadata Platform (XMP) metadata associated with the image. This property facilitates the extraction, modification, or addition of metadata, enabling comprehensive management of image-related information.
public override XmpPacketWrapper XmpData { get; set; }
Property Value
- XmpPacketWrapper
The XMP metadata.
Methods
GetDefaultOptions(object[])
Gets the default options.
public override ImageOptionsBase GetDefaultOptions(object[] args)
Parameters
args
object[]The arguments.
Returns
- ImageOptionsBase
Default options
GetModifyDate(bool)
Retrieves the timestamp indicating the most recent modification of the resource image. This method provides access to vital metadata, enabling applications to ascertain when the image was last altered, facilitating version tracking and content management.
public override DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
boolif set to
true
uses the information from FileInfo as default value.
Returns
- DateTime
The date and time the resource image was last modified.
GetOriginalOptions()
Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save(string) method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save(string, ImageOptionsBase) method as the second parameter.
public override ImageOptionsBase GetOriginalOptions()
Returns
- ImageOptionsBase
The options based on the original file settings.
OnPaletteChanged(IColorPalette, IColorPalette)
Called when palette is changed.
protected override void OnPaletteChanged(IColorPalette oldPalette, IColorPalette newPalette)
Parameters
oldPalette
IColorPaletteThe old palette.
newPalette
IColorPaletteThe new palette.
SaveData(Stream)
The save data.
protected override void SaveData(Stream stream)
Parameters
stream
StreamThe stream.
UpdateDimensions(int, int)
The update dimensions.
protected override void UpdateDimensions(int newWidth, int newHeight)
Parameters
UpdateMetadata()
Updates the image last modification date and time.
protected override void UpdateMetadata()