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

PNG File Format

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 (which is not actual nowadays, since appropriate patent has been expired in 2004). For the Web, PNG really has three main advantages over GIF :

  • alpha channels (variable transparency),
  • gamma correction (cross-platform control of image brightness),
  • two-dimensional interlacing (a method of progressive display).

Format Name

PNG

MIME Type

image/png

File Extensions

*.png

Supported Pixel Formats

Description Read Write
1 bit palette-based Yes Yes
4 bit palette-based Yes Yes
8 bit palette-based Yes Yes
8 bit grayscale Yes Yes
16 bit grayscale with the alpha channel Yes Yes
24 bit RGB Yes Yes
32 bit RGB with the alpha channel Yes Yes
48 bit RGB (16 bits per channel) Yes Yes
64 bit RGB with the alpha channel (16 bits per channel) Yes Yes

Encoder Options

Name Default Value Comments
PngEncoderOptions.Interlaced
PngFrame.Interlaced
false Value that specifies if the PNG file should be interlaced.

Examples

Loading PNG Files

The simplest way to load the PNG file is to pass its name to the constructor:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.png")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.png");

Alternatively, if you already have an instance of the Bitmap, you can use Load method:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap
bitmap.Load("c:\Mountain.png")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap();
bitmap.Load(@"c:\Mountain.png");

Saving PNG Files

The code below converts the JPEG file into the PNG. It also demonstrates how to change PNG encoder settings.

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

bitmap.Save("C:\Mountain.png", _
    New Aurigma.GraphicsMill.Codecs.PngEncoderOptions(True))

bitmap.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    bitmap.Save(@"C:\Mountain.png", 
        new Aurigma.GraphicsMill.Codecs.PngEncoderOptions(true));
}

Also you can use PngWriter class instead of the Save 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);                    
        }
    }        
}

Palette-based PNG Files

This code example 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)

bitmap.Save("C:\Mountain.png", _
    New Aurigma.GraphicsMill.Codecs.PngEncoderOptions(True))
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);

    bitmap.Save(@"C:\Mountain.png", 
        new Aurigma.GraphicsMill.Codecs.PngEncoderOptions(true));
}

The code below does the same, but using PngWriter class.

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);
        }
    }
}