Skip to content
C# .NET Standard PNG decoder and PNG library
Branch: master
Clone or download
EliotJones version 1.0.1
* use package icon and license expression settings for nuget package
* fix writing deflate stream content to be zlib compatible when creating png images
* add convenience methods for most common image creation use cases
* add convenience method to open png image from file path
Latest commit 2c34a1d Dec 17, 2019

Big Gustave

Build status

Open, read and create PNG images in fully managed C#.


To open a PNG image from file and get some pixel values:

using (var stream = File.OpenRead(@"C:\my\file\path\file.png"))
    Png image = Png.Open(stream);

    Pixel pixel = image.GetPixel(image.Width - 1, image.Height - 1);

    int pixelRedAverage = 0;

    pixelRedAverage += pixel.R;

    pixel = image.GetPixel(0, 0);

    pixelRedAverage += pixel.R;

    Console.WriteLine(pixelRedAverage / 2.0);       

The PNG object has methods to inspect the header and get the pixel values. The header has properties for:


The PNG also has width and height as convenience properties from the header information:

png.Width == png.Header.Width
png.Height == png.Header.Height

And a property that indicates if the image uses transparency:


To get a pixel use:

Pixel pixel = png.GetPixel(0, 7);

Where the first argument is x (column) and the second is y (row). The Pixel is used for all image types, e.g. Grayscale, Colour, with/without transparency.


To create a PNG use:

var builder = PngBuilder.Create(2, 2, false);

var red = new Pixel(255, 0, 0);

builder.SetPixel(red, 0, 0);
builder.SetPixel(255, 120, 16, 1, 1);

using (var memory = new MemoryStream())
    return memory.ToArray();
You can’t perform that action at this time.