Giter Site home page Giter Site logo

biggustave's Introduction

Big Gustave

NuGet

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

Usage

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:

png.Header.Width
png.Header.Height
png.Header.BitDepth
png.Header.ColorType
png.Header.CompressionMethod
png.Header.FilterMethod
png.Header.InterlaceMethod

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:

png.HasAlphaChannel

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.

Creation

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())
{
    builder.Save(memory);

    return memory.ToArray();
}

You can also load a PNG into a builder which will copy all the pixel values into the builder for easy editing:

var png = Png.Open(@"C:\files\my.png");
var builder = PngBuilder.FromPng(png);

biggustave's People

Contributors

eliotjones avatar roobixx avatar zanedubya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.