Java Advanced Imaging (henceforth referred to as just JAI) is a relatively old (hasn't been updated since 2006) package used for advanced image manipulation. Working with images has been built into Java Swing, but the functions provided aren't...everything...that you might need to do.
According to the readme provided with version 1.1.3, JAI does the following:
Java Advanced Imaging extends the imaging functionality provided in the
Java 2D API by providing a more flexible and scalable architecture
targeted for complex, high performance imaging requirements.
I find myself taking a class where JAI is a required library, and that means I need to install it on my computer.
First off, the download location:
http://www.oracle.com/technetwork/java/current-142188.html
I have a Windows 7 64-bit computer, so this could get a bit interesting. Looks like there are instructions for setting it up on 64-bit Solaris, so hopefully there won't be too many issues.
I decided to download this file:
jai-1_1_3-lib-windows-i586.exe.
Step 1: Run the installer.
- It's one of those old-style installers built using InstallShield.
- Use the default installation location of: C:\Program Files (x86)\Sun Microsystems\Java Advanced Imaging 1.1.3\
- And do a "complete" install.
That produces a directory with the following files:
JAR files:
jai_codec.jar
jai_core.jar
mlibwrapper_jai.jar
DLL files:
mlib_jai.dll
mlib_jai_mmx.dll
mlib_jai_util.dll
Step 2: Test the install by getting a "Hello World" program working.
Let's fire up Eclipse (Luna, x64) and see what can be done....
Eclipse is setup to use its own built in compiler at a compliance level of 1.7.
I have set Eclipse up with the JRE built into my installed JDK, so the JRE that we're going to use for the first test is an x64 JDK 1.7.0_51.
I found an example test application at this URL:
http://jai-api.blogspot.ca/ (JAISampleProgram) which looks like it's reasonably short.
Copy the code into Eclipse and add all three JAR files from the JAI install location in step 1 to the classpath. When I save the code it now compiles.
Change the location of the image to load to a file that actually exists. I'm using a random jpeg.
Click Run (or Debug) and wow, it works!
That's a 10% scale in both X and Y dimensions of my source image. Note that since nobody bothered to code the X button to actually do anything you'll have to kill the app through Eclipse or the command line.
When I ran the application, I got the following error:
Error: Could not load mediaLib accelerator wrapper classes. Continuing in pure Java mode.
Occurs in: com.sun.media.jai.mlib.MediaLibAccessor
com.sun.media.jai.mlib.MediaLibLoadException
Sounds like native acceleration isn't working. I don't really care at this point if it works or not, so let's just get rid of that warning....
static
{
System.setProperty("com.sun.media.jai.disableMediaLib", "true");
}
There are other ways to get rid of it too, as described on this post:
https://www.java.net/node/666373
And there we have it. Apparently JAI does indeed run in an x64 bit environment. Can't say the same for JMF, which is another one of my required libraries, so this will be getting demoted to x86 when I start doing actual development.