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 :
PNG
image/png
*.png
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 |
Name | Default Value | Comments |
---|---|---|
PngEncoderOptions.Interlaced
PngFrame.Interlaced |
false
|
Value that specifies if the PNG file should be interlaced. |
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")
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:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap bitmap.Load("c:\Mountain.png")
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(); bitmap.Load(@"c:\Mountain.png");
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()
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:
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()
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 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))
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()
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); } } }