Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java Tiff to jpg

2750374Dec 22 2014 — edited Dec 23 2014

I have a table in my database that contains Tiff images stored in blobs. I am trying to display these within an ADF web application. I'm running 12.1.2. It looks like the only way i can do this is by converting the tiff images to jpgs.

If i print out  ImageIO.getReaderFormatNames() i dont show a tiff reader. Which makes sense that i'm getting an error java.lang.IllegalArgumentException: image == null!

From what i understand i need a java advance imaging (JAI) plugin for tiff files. I have tried including a jai jar but with no luck. Can anyone point me in the right direction.

  1. private void getImageFromDB2(HttpServletRequest request, OutputStream os){
  2.     Connection conn = null;
  3.     String id = request.getParameter("id");
  4.     try {
  5.         //make connection to DB
  6.         Context ctx = new InitialContext();
  7.         DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/****");
  8.         conn = ds.getConnection();
  9.         
  10.         PreparedStatement statement =
  11.             conn.prepareStatement("SELECT image " + "FROM images " + "WHERE PIC_ID = ?");
  12.         statement.setLong(1, new Long(id));
  13.         ResultSet rs = statement.executeQuery();
  14.         if (rs.next()) {
  15.             Blob blob = rs.getBlob("image");
  16.             ImageIO.write(ImageIO.read(blob.getBinaryStream()), "jpg", os);
  17.             os.close();
  18.         }
  19.     } catch (Exception e) {
  20.         System.out.println(e);
  21.     } finally {
  22.         try {
  23.             if (conn != null) {
  24.                 conn.close();
  25.             }
  26.         } catch (SQLException sqle) {
  27.             System.out.println("SQLException error");
  28.         }
  29.     }
  30. }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2015
Added on Dec 22 2014
9 comments
1,860 views