Class PngImage
Contents
[
Hide
]PngImage class
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
Constructors
Name | Description |
---|---|
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Properties
Name | Description |
---|---|
AutoAdjustPalette { get; set; } | Gets or sets a value indicating whether automatic adjust palette. |
override BackgroundColor { get; set; } | 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. |
override BitsPerPixel { get; } | 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. |
Bounds { get; } | Gets the image bounds. |
BufferSizeHint { get; set; } | Gets or sets the buffer size hint which is defined max allowed size for all internal buffers. |
Container { get; } | Gets the Image container. |
DataStreamContainer { get; } | Gets the object’s data stream. |
Disposed { get; } | Gets a value indicating whether this instance is disposed. |
override FileFormat { get; } | 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. |
override HasAlpha { get; } | 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. |
override HasBackgroundColor { get; set; } | 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. |
override HasTransparentColor { get; set; } | 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. |
override Height { get; } | 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. |
override HorizontalResolution { get; set; } | 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. |
virtual ImageOpacity { get; } | Gets opacity of this image. |
Interlaced { get; } | 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. |
InterruptMonitor { get; set; } | Gets or sets the interrupt monitor. |
override IsCached { get; } | Gets a value indicating whether image data is cached currently. |
IsInterlaced { get; } | 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. |
IsRawDataAvailable { get; } | Gets a value indicating whether raw data loading is available. |
Palette { get; set; } | Gets or sets the color palette. The color palette is not used when pixels are represented directly. |
virtual PremultiplyComponents { get; set; } | Gets or sets a value indicating whether the image components must be premultiplied. |
RawCustomColorConverter { get; set; } | Gets or sets the custom color converter |
override RawDataFormat { get; } | 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. |
RawDataSettings { get; } | Gets the current raw data settings. Note when using these settings the data loads without conversion. |
RawFallbackIndex { get; set; } | Gets or sets the fallback index to use when palette index is out of bounds |
RawIndexedColorConverter { get; set; } | Gets or sets the indexed color converter |
virtual RawLineSize { get; } | Gets the raw line size in bytes. |
Size { get; } | Gets the image size. |
override TransparentColor { get; set; } | 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. |
virtual UpdateXmpData { get; set; } | Gets or sets a value indicating whether to update the XMP metadata. |
override UsePalette { get; } | Gets a value indicating whether the image palette is used. |
virtual UseRawData { get; set; } | Gets or sets a value indicating whether to use raw data loading when the raw data loading is available. |
override VerticalResolution { get; set; } | 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. |
override Width { get; } | 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 |
override XmpData { get; set; } | 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. |
Methods
Name | Description |
---|---|
override AdjustBrightness(int) | Adjust of a brightness for image. |
override AdjustContrast(float) | Image contrasting |
override AdjustGamma(float) | Gamma-correction of an image. |
override AdjustGamma(float, float, float) | Gamma-correction of an image. |
override BinarizeBradley(double) | Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding |
override BinarizeBradley(double, int) | Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding |
override BinarizeFixed(byte) | Binarization of an image with predefined threshold |
override BinarizeOtsu() | Binarization of an image with Otsu thresholding |
Blend(Point, RasterImage, byte) | Blends this image instance with the overlay image. |
override Blend(Point, RasterImage, Rectangle, byte) | Blends this image instance with the overlay image. |
override CacheData() | Caches the data and ensures no additional data loading will be performed from the underlying DataStreamContainer . |
CanSave(ImageOptionsBase) | Determines whether image can be saved to the specified file format represented by the passed save options. |
override Crop(Rectangle) | Cropping the image. |
virtual Crop(int, int, int, int) | Crop image with shifts. |
Dispose() | Disposes the current instance. |
Dither(DitheringMethod, int) | Performs dithering on the current image. |
override Dither(DitheringMethod, int, IColorPalette) | Performs dithering on the current image. |
virtual Filter(Rectangle, FilterOptionsBase) | Filters the specified rectangle. |
GetArgb32Pixel(int, int) | Gets an image 32-bit ARGB pixel. |
GetDefaultArgb32Pixels(Rectangle) | Gets the default 32-bit ARGB pixels array. |
override GetDefaultOptions(object[]) | Gets the default options. |
GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) | Gets the default pixels array using partial pixel loader. |
GetDefaultRawData(Rectangle, RawDataSettings) | Gets the default raw data array. |
GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) | Gets the default raw data array using partial pixel loader. |
override 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. |
override 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 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 method as the second parameter. |
GetPixel(int, int) | Gets an image pixel. |
virtual GetSerializedStream(ImageOptionsBase, Rectangle, out int) | Converts to aps. |
GetSkewAngle() | Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning. |
override Grayscale() | Transformation of an image to its grayscale representation |
LoadArgb32Pixels(Rectangle) | Loads 32-bit ARGB pixels. |
LoadArgb64Pixels(Rectangle) | Loads 64-bit ARGB pixels. |
LoadCmyk32Pixels(Rectangle) | Loads pixels in CMYK format. |
LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) | Loads 32-bit ARGB pixels partially by packs. |
LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) | Loads 64-bit ARGB pixels partially by packs. |
LoadPartialPixels(Rectangle, IPartialPixelLoader) | Loads pixels partially by packs. |
LoadPixels(Rectangle) | Loads pixels. |
LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) | Loads raw data. |
LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) | Loads raw data. |
NormalizeAngle() | Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods. |
virtual NormalizeAngle(bool, Color) | Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate methods. |
ReadArgb32ScanLine(int) | Reads the whole scan line by the specified scan line index. |
ReadScanLine(int) | Reads the whole scan line by the specified scan line index. |
override RemoveMetadata() | Removes this image instance metadata by setting this XmpData value to null . |
ReplaceColor(Color, byte, Color) | Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges. |
virtual ReplaceColor(int, byte, int) | Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges. |
ReplaceNonTransparentColors(Color) | Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one. |
virtual ReplaceNonTransparentColors(int) | Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one. |
Resize(int, int) | Resizes the image. The default NearestNeighbourResample is used. |
override Resize(int, int, ImageResizeSettings) | Resizes the image. |
override Resize(int, int, ResizeType) | Resizes the image. |
ResizeHeightProportionally(int) | Resizes the height proportionally. The default NearestNeighbourResample is used. |
virtual ResizeHeightProportionally(int, ImageResizeSettings) | Resizes the height proportionally. |
virtual ResizeHeightProportionally(int, ResizeType) | Resizes the height proportionally. |
ResizeWidthProportionally(int) | Resizes the width proportionally. The default NearestNeighbourResample is used. |
virtual ResizeWidthProportionally(int, ImageResizeSettings) | Resizes the width proportionally. |
virtual ResizeWidthProportionally(int, ResizeType) | Resizes the width proportionally. |
virtual Rotate(float) | Rotate image around the center. |
override Rotate(float, bool, Color) | Rotate image around the center. |
override RotateFlip(RotateFlipType) | Rotates, flips, or rotates and flips the image. |
Save() | Saves the image data to the underlying stream. |
Save(Stream) | Saves the object’s data to the specified stream. |
override Save(string) | Saves the image to the specified file location. |
Save(Stream, ImageOptionsBase) | Saves the image’s data to the specified stream in the specified file format according to save options. |
virtual Save(string, bool) | Saves the object’s data to the specified file location. |
virtual Save(string, ImageOptionsBase) | Saves the object’s data to the specified file location in the specified file format according to save options. |
override Save(Stream, ImageOptionsBase, Rectangle) | Saves the image’s data to the specified stream in the specified file format according to save options. |
virtual Save(string, ImageOptionsBase, Rectangle) | Saves the object’s data to the specified file location in the specified file format according to save options. |
SaveArgb32Pixels(Rectangle, int[]) | Saves the 32-bit ARGB pixels. |
SaveCmyk32Pixels(Rectangle, int[]) | Saves the pixels. |
SavePixels(Rectangle, Color[]) | Saves the pixels. |
SaveRawData(byte[], int, Rectangle, RawDataSettings) | Saves the raw data. |
SetArgb32Pixel(int, int, int) | Sets an image 32-bit ARGB pixel for the specified position. |
override SetPalette(IColorPalette, bool) | Sets the image palette. |
SetPixel(int, int, Color) | Sets an image pixel for the specified position. |
virtual SetResolution(double, double) | Sets the resolution for this RasterImage . |
virtual ToBitmap() | Converts raster image to the bitmap. This method is not supported in versions from .Net7.0 and higher |
WriteArgb32ScanLine(int, int[]) | Writes the whole scan line to the specified scan line index. |
WriteScanLine(int, Color[]) | Writes the whole scan line to the specified scan line index. |
Examples
This example shows how to load a PNG image from a file.
[C#]
string dir = "c:\\temp\\";
// Load a PNG image from a file.
using (Aspose.Imaging.FileFormats.Png.PngImage pngImage = new Aspose.Imaging.FileFormats.Png.PngImage(dir + "sample.png"))
{
// Transform the image to grayscale representation
pngImage.Grayscale();
// Save to a file.
pngImage.Save(dir + "sample.grayscale.png");
}
See Also
- class RasterCachedImage
- namespace Aspose.Imaging.FileFormats.Png
- assembly Aspose.Imaging