Reputation: 409
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!
Upvotes: 4
Views: 3901
Reputation: 1766
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.
Upvotes: 0
Reputation: 409
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);
Upvotes: 4