Table of Contents

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 PngOptions

The png options.

width int

The width.

height int

The 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 RasterImage

The 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 RasterImage

The raster image.

colorType PngColorType

The 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 Stream

The 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

width int

The width.

height int

The height.

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 int

The width.

height int

The height.

colorType PngColorType

The 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 string

The 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 string

The path to load an image.

colorType PngColorType

The color type.

Exceptions

ArgumentNullException

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

Color

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

int

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

FileFormat

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

bool

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

bool

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

int

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

double

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

PixelDataFormat

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

Color

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

double

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

int

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 bool

if 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 IColorPalette

The old palette.

newPalette IColorPalette

The new palette.

SaveData(Stream)

The save data.

protected override void SaveData(Stream stream)

Parameters

stream Stream

The stream.

UpdateDimensions(int, int)

The update dimensions.

protected override void UpdateDimensions(int newWidth, int newHeight)

Parameters

newWidth int

The new width.

newHeight int

The new height.

UpdateMetadata()

Updates the image last modification date and time.

protected override void UpdateMetadata()