Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eliotjones/biggustave
C# .NET Standard PNG decoder and PNG library
https://github.com/eliotjones/biggustave
csharp png
Last synced: 6 days ago
JSON representation
C# .NET Standard PNG decoder and PNG library
- Host: GitHub
- URL: https://github.com/eliotjones/biggustave
- Owner: EliotJones
- License: unlicense
- Created: 2019-03-23T20:37:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T12:13:52.000Z (7 months ago)
- Last Synced: 2024-04-28T08:12:23.901Z (7 months ago)
- Topics: csharp, png
- Language: C#
- Homepage:
- Size: 5.73 MB
- Stars: 64
- Watchers: 4
- Forks: 18
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Big Gustave
![NuGet](https://img.shields.io/nuget/dt/BigGustave?style=flat-square)
#### Open, read and create PNG images in fully managed C#.
## Usage - **Reading**
To open a PNG image from a file and get some pixel values:
```csharp
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 multiple methods to inspect the header and get the pixel values. The header has properties for:
------```csharp
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:**
```csharp
png.Width == png.Header.Width
png.Height == png.Header.Height
```**And a property that indicates whether the image uses transparency:**
```csharp
png.HasAlphaChannel
```#### To get a pixel use:
```csharp
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 types of images (e.g. Grayscale, Color, with / without transparency)
-----
## Usage - **Creating**
Generating a PNG image:
```csharp
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 load a PNG image into a builder which will copy all the pixels values into the builder for easier editing:**
```csharp
var png = Png.Open(@"C:\files\my.png");
var builder = PngBuilder.FromPng(png);
```