While working with Images we often think images I/O is similar to any other File I/O, I recently faced a situation when I had to work with Images in Java.
There might be several other ways to do it, I liked it through ImageIO utility.
1: //read it from a file.
2: BufferedImage fromFile = ImageIO.read(new File("path to the file"));
3: //read it from an InputStream
4: Buffered fromIs = ImageIO.read(new FileInputStream("path to the file"));
5: //read it from a URL
6: Buffered fromUrl = ImageIO.read(new URL("a URL for the image"));
1: //Read the Image from a byte Array - I am assuming the Image coming from a stream
2: BufferedImage image = ImageIO.read(new ByteArrayOutputStream(bytearray));
3: //Write the image to a file
4: ImageIO.write(image,"GIF",new FileOutputStream("path to the file"));
Creating a rich statistical application can become very handy and useful once you integrate Java with R.
Integration needs following to be installed already:
- JDK 1.5 or above ( I tried with 1.6 )
- R – can be downloaded from CRAN
- R_HOME environment variable is set.
Here is how you can integrate and configure your java to work with R:
- From R install the rJava package ( can be easily be done with install command in R ). The latest rJava contains JRI implicit so no need to download it manually.
- Go to the download directory of R and you can see the rJava directory, and inside that there will be JRI directory include that in your java.library.path
And you are done 🙂