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

JPEG2000 File Format

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.

Format Name

JPEG2000

MIME Type

image/jp2

File Extensions

*.jp2

Supported Pixel Formats

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

Encoder Options

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.

Examples

Loading JPEG2000 Files

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

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jp2")
C#
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:

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

Saving JPEG2000 files

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:

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

bitmap.Save("C:\Mountain2.jp2", _
    New Aurigma.GraphicsMill.Codecs.Jpeg2kEncoderOptions(0.1))

bitmap.Dispose()
C#
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:

Visual Basic
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()
C#
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);
        }
    }
}