JPEG2000 is a relatively young coding standard. It implements a wavelet-based compression which provides outstanding compression ratio with relatively high quality (as compared to other lossy compression algorithms). The only disadvantage of this format is that it is not wide spread yet.
JPEG2000
image/jp2
*.jp2
Description | Read | Write |
---|---|---|
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 |
16 bit grayscale (16 bits per channel) | Yes | Yes |
32 bit grayscale with the alpha channel (16 bits per 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 |
---|---|---|
Jpeg2kEncoderOptions.Compression
Jpeg2kFrame.Compression |
CompressionType.WaveletLossless | Value that specifies a JPEG2000 compression type (lossless or lossy). |
Jpeg2kEncoderOptions.ProgressionOrder
Jpeg2kFrame.ProgressionOrder |
Jpeg2kProgressionOrder.RateScalable | Progression order (packets ordering in the code stream). |
Jpeg2kEncoderOptions.Rate
Jpeg2kFrame.Rate |
1 | Compression ratio (in range from 0 to 1). |
Jpeg2kEncoderOptions.TileHeight
Jpeg2kFrame.TileHeight |
0 | JPEG2000 tile width. |
Jpeg2kEncoderOptions.TileWidth
Jpeg2kFrame.TileWidth |
0 | JPEG2000 tile height. |
The simplest way to load the JPEG2000 file is to pass its name to the constructor:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jp2")
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jp2");
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.jp2")
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(); bitmap.Load(@"c:\Mountain.jp2");
This code example demonstrates how to save the JPEG2000 file with non-default encoder settings. Here we use high compression. The result file size will be only 10% from the original size:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg") bitmap.Save("C:\Mountain2.jp2", _ New Aurigma.GraphicsMill.Codecs.Jpeg2kEncoderOptions(0.1)) bitmap.Dispose()
using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg")) { bitmap.Save(@"C:\Mountain2.jp2", new Aurigma.GraphicsMill.Codecs.Jpeg2kEncoderOptions(0.1f)); }
Also you can use Codecs.Jpeg2kWriter class instead of the Save method of the Bitmap. In particular it enables you to save the image asynchronously.
The Codecs.Jpeg2kWriter class usage is demonstrated below:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg") Dim writer As New Aurigma.GraphicsMill.Codecs.Jpeg2kWriter("C:\Mountain2.jp2") Dim frame As New Aurigma.GraphicsMill.Codecs.Jpeg2kFrame frame.Rate = 0.1 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.Jpeg2kWriter writer = new Aurigma.GraphicsMill.Codecs.Jpeg2kWriter()) { writer.Open(@"C:\Mountain2.jp2"); using (Aurigma.GraphicsMill.Codecs.Jpeg2kFrame frame = new Aurigma.GraphicsMill.Codecs.Jpeg2kFrame()) { frame.Rate = 0.1f; frame.SetBitmap(bitmap); writer.AddFrame(frame); } } }