This documentation is for the old version. Go to the latest Graphics Mill docs

PngWriter Class

This class enables you to write PNG images.

Namespace: Aurigma.GraphicsMill.Codecs
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

Visual Basic
Public NotInheritable Class PngWriter _
	Inherits FormatWriter
C#
public sealed class PngWriter : FormatWriter

Remarks

The Portable Network Graphics (PNG) format was designed to replace the older and simpler GIF format and, to some extent, the much more complex TIFF format. Besides of it, PNG was developed to avoid legal problems which was caused by LZW algorithm used in GIF and sometimes in TIFF. For the Web, PNG really has four main advantages over GIF:

  • Alpha channel support (variable transparency);Gamma correction (cross-platform control of image brightness);Two-dimensional interlacing (a method of progressive display);In general it has higher compression ratio comparing to GIF (and still lossless);

PNG supports images of most Graphics Mill for .NET pixel formats (indexed, grayscale, and RGB, including extended versions). Being web-oriented, it does not support CMYK images. Only single bitmap can be stored into single PNG file (i.e. it has no multiple frames support).

Examples

Also you can use PngWriter class instead of the Save(String, IEncoderOptions) method of the Bitmap. In particular it enables you to save the image asynchronously.

The PngWriter class usage is demonstrated below:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

Dim writer As New Aurigma.GraphicsMill.Codecs.PngWriter("C:\Mountain.png")

Dim frame As New Aurigma.GraphicsMill.Codecs.PngFrame
frame.Interlaced = True
frame.SetBitmap(bitmap)

bitmap.Dispose()

writer.AddFrame(frame)

frame.Dispose()

writer.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
        new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    using (Aurigma.GraphicsMill.Codecs.PngWriter writer = 
            new Aurigma.GraphicsMill.Codecs.PngWriter(@"C:\Mountain.png"))
    {
        using (Aurigma.GraphicsMill.Codecs.PngFrame frame = 
                   new Aurigma.GraphicsMill.Codecs.PngFrame())
        {
            frame.Interlaced = true;
            frame.SetBitmap(bitmap);
        
            writer.AddFrame(frame);                    
        }
    }        
}

This code sample converts the image into the indexed bitmap with 32 palette entries. After that it saves this bitmap into the PNG file.

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

bitmap.ColorManagement.PaletteEntryCount = 32
bitmap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, _
    Nothing)

Dim writer As New Aurigma.GraphicsMill.Codecs.PngWriter("C:\Mountain.png")

Dim frame As New Aurigma.GraphicsMill.Codecs.PngFrame
frame.Interlaced = True
frame.SetBitmap(bitmap)

bitmap.Dispose()

writer.AddFrame(frame)

frame.Dispose()

writer.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
        new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    bitmap.ColorManagement.PaletteEntryCount = 32;
    bitmap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, 
        null);

    using (Aurigma.GraphicsMill.Codecs.PngWriter writer = 
            new Aurigma.GraphicsMill.Codecs.PngWriter(@"C:\Mountain.png"))
    {
        using (Aurigma.GraphicsMill.Codecs.PngFrame frame = 
                   new Aurigma.GraphicsMill.Codecs.PngFrame())
        {
            frame.Interlaced = true;
            frame.SetBitmap(bitmap);

            writer.AddFrame(frame);
        }
    }
}

Inheritance Hierarchy

Thread Safety

Static members of this type are safe for multi-threaded operations. Instance members of this type are safe for multi-threaded operations.

Object Model





Supported Pixel Formats

Member NameDescription
Format1bppIndexed1 bit per pixel. Indexed.
Format4bppIndexed4 bits per pixel. Indexed.
Format8bppIndexed8 bits per pixel. Indexed.
Format8bppGrayScale8 bits per pixel. Grayscale. 8 bits are used for luminosity level.
Format16bppGrayScale16 bits per pixel. Grayscale. All 16 bits are used for luminosity level (extended pixel format).
Format16bppAGrayScale16 bits per pixel. Grayscale with alpha channel. 8 bits are used for alpha channel and other 8 bits are used for luminosity level.
Format32bppAGrayScale32 bits per pixel. Grayscale with alpha channel. 16 bits are used for alpha channel and other 16 bits are used for luminosity level (extended pixel format).
Format24bppRgb24 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components.
Format32bppRgb32 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components. The rest 8 bits are unused.
Format32bppArgb32 bits per pixel. RGB with alpha channel. 8 bits each are used for the alpha, red, green, and blue components.
Format48bppRgb48 bits per pixel. RGB. 16 bits each are used for the red, green, and blue components (extended pixel format).
Format64bppArgb64 bits per pixel. RGB with alpha channel. 16 bits each are used for the alpha, red, green, and blue components (extended pixel format).

See Also

Reference