Exemplo n.º 1
0
 /**
  * @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();
     }
   }
 }
Exemplo n.º 2
0
 public static void reencode(String orig, FilterType filterType, int cLevel) {
   long t0 = System.currentTimeMillis();
   String suffix =
       filterType.toString().replace("FILTER_", "").toLowerCase() + "_" + String.valueOf(cLevel);
   String dest = orig.replaceAll("\\.png$", "") + "_" + suffix + ".png";
   PngReader pngr = FileHelper.createPngReader(new File(orig));
   PngWriter pngw = FileHelper.createPngWriter(new File(dest), pngr.imgInfo, true);
   pngw.setFilterType(filterType);
   pngw.setCompLevel(cLevel);
   pngw.copyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL);
   for (int row = 0; row < pngr.imgInfo.rows; row++) {
     ImageLine l1 = pngr.readRow(row);
     pngw.writeRow(l1, row);
   }
   pngr.end();
   pngw.copyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL);
   pngw.end();
   long t1 = System.currentTimeMillis();
   long size0 = (new File(orig)).length();
   long size1 = (new File(dest)).length();
   double sizerel = (size1 * 1000.0) / size0;
   System.out.printf("%s\t%d\t%.2f\n", dest, (t1 - t0), sizerel);
 }