PngChunk Class

An immutable ancillary chunk of a PNG file that the library does not interpret (a private chunk, or a public chunk such as gAMA, bKGD or tIME that it reads into no other metadata): its type, its data and its position.

public sealed class PngChunk : IEquatable<PngChunk>

Remarks

The case of the letters of the type carries its properties (PNG specification, section 5.4): an ancillary chunk has a lowercase first letter, a private chunk a lowercase second letter, and a chunk that can be copied whatever the changes to the image has a lowercase fourth letter (PngChunk.IsSafeToCopy). The third letter is uppercase.

PngEncoder writes the chunks at their position. Because it encodes the image data again, it only writes the chunks that are safe to copy unless PngEncoder.WriteUnsafeToCopyChunks says that the others still describe the image (PNG specification, section 14.2). The other encoders ignore the chunks.

Implements

Constructors

NameDescription
PngChunk(string, MetadataBlob, PngChunkPosition)Initializes a new instance of the PngChunk class.

PngChunk(string, MetadataBlob, PngChunkPosition)

PngChunk.cs

Initializes a new instance of the PngChunk class.

public PngChunk(string type, MetadataBlob data, PngChunkPosition position = PngChunkPosition.BeforeImageData)

Parameters

type string
The type: four ASCII letters, the first lowercase (ancillary) and the third uppercase.
data MetadataBlob
The data of the chunk, without its length, type and CRC.
position PngChunkPosition
Where the chunk is written relative to the critical chunks.

Exceptions

ArgumentNullException
type or data is null.
ArgumentException
type is not four ASCII letters, is a critical chunk (uppercase first letter), has a lowercase third letter (reserved), or is a chunk the library reads or writes itself (tRNS, pHYs, iCCP, cICP, mDCV, cLLI, eXIf, tEXt, zTXt, iTXt, acTL, fcTL, fdAT).
ArgumentOutOfRangeException
position is not a defined PngChunkPosition.

Properties

NameDescription
DataGets the data of the chunk.
IsPrivateGets a value indicating whether the chunk is private (a lowercase second letter), rather than defined by the PNG specification or registered.
IsSafeToCopyGets a value indicating whether the chunk can be copied to a file whose image data changed (a lowercase fourth letter): otherwise it depends on the image data, and is only valid for the image it was written with.
PositionGets where the chunk lies relative to the critical chunks.
TypeGets the type of the chunk: four ASCII letters.

Gets the data of the chunk.

public MetadataBlob Data { get; }

Property value

MetadataBlob

IsPrivate

PngChunk.cs

Gets a value indicating whether the chunk is private (a lowercase second letter), rather than defined by the PNG specification or registered.

public bool IsPrivate { get; }

Property value

bool

IsSafeToCopy

PngChunk.cs

Gets a value indicating whether the chunk can be copied to a file whose image data changed (a lowercase fourth letter): otherwise it depends on the image data, and is only valid for the image it was written with.

public bool IsSafeToCopy { get; }

Property value

bool

Position

PngChunk.cs

Gets where the chunk lies relative to the critical chunks.

public PngChunkPosition Position { get; }

Property value

PngChunkPosition

Gets the type of the chunk: four ASCII letters.

public string Type { get; }

Property value

string

Methods

NameDescription
Equals(PngChunk?)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Determines whether the specified object is equal to the current object.
GetHashCode()Serves as the default hash function.
ToString()Returns a string that represents the current object.

Equals overloads

Equals(PngChunk?)

PngChunk.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(PngChunk? other)
Parameters
other PngChunk?
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

PngChunk.cs

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current object.
Returns

bool true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

PngChunk.cs

Serves as the default hash function.

public override int GetHashCode()

Returns

int A hash code for the current object.

ToString()

PngChunk.cs

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.