Package org.geoforge.ioogc.javax.imageio

Source Code of org.geoforge.ioogc.javax.imageio.GfrUtlImgIoOgc

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.ioogc.javax.imageio;

import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;
import org.geoforge.java.io.file.GfrUtilFile;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;

/*
* could be moved in the future to be shared by other stuff
*/

/**
*
* @author bill
*/
public class GfrUtlImgIoOgc
{
    // ----
   // begin: instantiate logger for this class

   final static private Logger _LOGGER_ = Logger.getLogger(GfrUtlImgIoOgc.class.getName());

   static
   {
      GfrUtlImgIoOgc._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----
  
   
   static public Dimension s_getImageDimension(File fle) throws IOException
   {
      int intPos = fle.getName().lastIndexOf(".");

      if (intPos == -1)
         throw new IOException("No extension for file: " + fle.getAbsolutePath());

      String strSuffixNameFile = fle.getName().substring(intPos + 1);

      Iterator<ImageReader> itrImageReader = ImageIO.getImageReadersBySuffix(strSuffixNameFile);

      if (itrImageReader.hasNext())
      {
         ImageReader irr = itrImageReader.next();

         try
         {
            ImageInputStream iis = new FileImageInputStream(fle);
            irr.setInput(iis);
            int intW = irr.getWidth(irr.getMinIndex());
            int intH = irr.getHeight(irr.getMinIndex());
            return new Dimension(intW, intH);
         }
        
         catch (IOException excIO)
         {
            excIO.printStackTrace();
            String strWarning = excIO.getMessage();
            strWarning += "\n " + fle.getAbsolutePath();
            GfrUtlImgIoOgc._LOGGER_.warning(strWarning);
         }
         finally
         {
            irr.dispose();
         }
      }

      String str = "Not a known image file: " + fle.getAbsolutePath();
      GfrUtlImgIoOgc._LOGGER_.warning(str);
      throw new IOException(str);
   }
   
   
    private GfrUtlImgIoOgc() {}
}
TOP

Related Classes of org.geoforge.ioogc.javax.imageio.GfrUtlImgIoOgc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.