Question

After reading Image from database, I need to convert that Image to JP2 (JPEG2000)

Update:

I used FreeImage to convert the image to JP2

   // Load bitmap           
   FIBITMAP dib = FreeImage.LoadEx(imageName);
// Check success
if (dib.IsNull)
{
    MessageBox.Show("Could not load Sample.jpg", "Error");
    return;
}    

// Convert Bitmap to JPEG2000 and save it on the hard disk
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, dib, "Image.jp2", FREE_IMAGE_SAVE_FLAGS.DEFAULT);

// Unload source bitmap
FreeImage.UnloadEx(ref dib);

Now, I need to compress this image with a high compression level!

Was it helpful?

Solution

I Found The Answer

   // Load bitmap           
   FIBITMAP dib = FreeImage.LoadEx(imageName);
    //
    Check success
    if (dib.IsNull)
    {
        MessageBox.Show("Could not load Sample.jpg", "Error");
        return;
    }    

    // Convert Bitmap to JPEG2000 and save it on the hard disk
    FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, dib, "Image.jp2", FREE_IMAGE_SAVE_FLAGS.EXR_PXR24 | FREE_IMAGE_SAVE_FLAGS.EXR_LC);

    // Unload source bitmap
    FreeImage.UnloadEx(ref dib);

OTHER TIPS

The flags for the JP2 (and J2K) formats is interpreted simply as a reduction factor. This is from the PluginJP2.cpp source

// if no rate entered, apply a 16:1 rate by default
if(flags == JP2_DEFAULT) {
    parameters.tcp_rates[0] = (float)16;
} else {
    // for now, the flags parameter is only used to specify the rate
    parameters.tcp_rates[0] = (float)(flags & 0x3FF);
}

So you can actually specify a reduction rate of up to 1023:1:

// Load bitmap           
FIBITMAP dib = FreeImage.LoadEx(imageName);
// Check success
if (dib.IsNull)
{
    MessageBox.Show("Could not load Sample.jpg", "Error");
    return;
}    

// Convert Bitmap to JPEG2000 and save it on the hard disk
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, dib, "Image.jp2", (FREE_IMAGE_SAVE_FLAGS)1023);

// Unload source bitmap
FreeImage.UnloadEx(ref dib);

This will give you a very small very low quality file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top