It seems that .NET can't open JP2 (Jpeg 2000) files using the GDI library. I've searched on google but can't find any libraries or example code to do this.
Anybody got any ideas? I don't really want to pay for a library to do it unless I have to..
Is JPEG 2000 still in use? JPEG 2000 is still in use — but it's one of the least adopted image formats. This has been the case throughout its history. Camera manufacturers and websites were reluctant to accept the JPEG 2000 format until it became more popular — effectively stunting its growth.
Filename extensions for Motion JPEG 2000 video files are . mj2 and . mjp2 according to RFC 3745. It is an open ISO standard and an advanced update to MJPEG (or MJ), which was based on the legacy JPEG format.
Today JPEG 2000 is used for its high quality and low latency in video over IP applications such as Contribution Links (live events to studio transmission) and recent IP-based broadcast studio infrastructures. Moreover, it is also used as the master format for content storage.
To open a . JP2 file, simply open the latest version of Photoshop and select your . JP2 file from your computer. Safari is the only web browser that supports JPEG 2000.
Seems like we can do it using FreeImage (which is free)
FIBITMAP dib = FreeImage.LoadEx("test.jp2"); //save the image out to disk FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, "test.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL); //or even turn it into a normal Bitmap for later use Bitmap bitmap = FreeImage.GetBitmap(dib);
For anyone coming across this old post, the above code from Gordon works great, but as jixtra pointed out, you will indeed get an exception: System.DllNotFoundException: 'Unable to load DLL 'FreeImage': The specified module could not be found.' when installing via nuget. I was able to get it working in .net 4.6.1 by installing the FreeImage-dotnet-core nuget package and manually adding the FreeImage.dll to the bin folder. You can download the dll here: http://freeimage.sourceforge.net/download.html.
I needed a better quality image to use with tesseract so I made a few minor changes which made a huge difference to the quality of the new jpeg:
var jp2Format = FREE_IMAGE_FORMAT.FIF_JP2; var dib = FreeImage.LoadEx("test.jp2", ref jp2Format); FreeImage.SetResolutionX(dib, 300); FreeImage.SetResolutionY(dib, 300); FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, "test.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With