---
title: "PNG File Format"
canonical: https://www.graphicsmill.com/docs/gm5/PNGFileFormat.htm
product: "Graphics Mill 5.5 for .NET"
---

This documentation is for the old version. [Go to the latest Graphics Mill docs](https://www.graphicsmill.com/docs/gm/)

# PNG File Format
 
The Portable Network Graphics (PNG) format was designed to replace the older and simpler [GIF](https://www.graphicsmill.com/docs/gm5/GIFFileFormat.htm.md) format and, to some extent, the much more complex [TIFF](https://www.graphicsmill.com/docs/gm5/TIFFFileFormat.htm.md) 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](https://www.graphicsmill.com/docs/gm5/GIFFileFormat.htm.md) :
 
- 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](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Codecs_PngEncoderOptions_Interlaced.htm.md) <br> [PngFrame.Interlaced](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Codecs_PngFrame_Interlaced.htm.md) |  `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:
 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.png")
```
 
```csharp
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.png");
```
 
Alternatively, if you already have an instance of the [Bitmap](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Bitmap.htm.md), you can use [Load](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Bitmap_Load.htm.md) method:
 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap
bitmap.Load("c:\Mountain.png")
```
 
```csharp
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.
 
```
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

bitmap.Save("C:\Mountain.png", _
    New Aurigma.GraphicsMill.Codecs.PngEncoderOptions(True))

bitmap.Dispose()
```
 
```csharp
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](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Codecs_PngWriter.htm.md) class instead of the [Save](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Bitmap_Save.htm.md) method of the Bitmap. In particular it enables you to save the image asynchronously.
 
The PngWriter class usage is demonstrated below:
 
```
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()
```
 
```csharp
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.
 
```
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))
```
 
```csharp
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.
 
```
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()
```
 
```csharp
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);
        }
    }
}
```
