// 画像分辨率取得
dimension = getImageDimension(filePathTemplate);
templateWidth = dimension.width;
templateHight = dimension.height;
/**
* 画像解像度取得.* @param path path
*
*/
private static Dimension getImageDimension(String path) {
Dimension result = null;
String suffix = getFileSuffix(path);
// デコードファイル
Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
if (iter.hasNext()) {
ImageReader reader = iter.next();
try {
ImageInputStream stream = new FileImageInputStream(new File(
path));
reader.setInput(stream);
int width = reader.getWidth(reader.getMinIndex());
int height = reader.getHeight(reader.getMinIndex());
result = new Dimension(width, height);
} catch (IOException e) {
e.printStackTrace();
} finally {
reader.dispose();
}
}
return result;
}
/**
* 画像拡張子取得.
* @param path path
*/
private static String getFileSuffix(final String path) {
String result = null;
if (path != null) {
result = "";
if (path.lastIndexOf('.') != -1) {
result = path.substring(path.lastIndexOf('.'));
if (result.startsWith(".")) {
result = result.substring(1);
}
}
}
return result;
}