/** * @param sampleLegendFile * @return */ private Dimension getSizeFromSample(File sampleLegendFile) { PngReader pngReader = null; try { // reads size using PNGJ reader, that can read metadata without reading // the full image pngReader = new PngReader(sampleLegendFile); return new Dimension(pngReader.imgInfo.cols, pngReader.imgInfo.rows); } finally { if (pngReader != null) { pngReader.close(); } } }