Example #1
0
 public static void storeTiledTiff(RenderedImage image, String filePath) {
   final TIFFEncodeParam encodeParam = new TIFFEncodeParam();
   encodeParam.setTileSize(image.getTileWidth(), image.getTileHeight());
   encodeParam.setWriteTiled(true);
   encodeParam.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
   System.out.println("Storing tiled TIFF image to " + filePath + "...");
   FileStoreDescriptor.create(image, filePath, "TIFF", encodeParam, false, null);
 }
  /**
   * This method permits to write the result image from the wms request in a tiff format
   *
   * @param wmsResponse The object used later to build the HTTP response.
   * @param output The output stream
   * @param img The output image
   * @throws IOException
   */
  private static void writeTIFF(
      WMSResponse wmsResponse, OutputStream output, BufferedImage img, double pixelSize)
      throws IOException {
    wmsResponse.setContentType(ImageFormats.TIFF.toString());
    int dpm = (int) (1000 / pixelSize + 1);
    long[] resolution = {dpm, 1};

    TIFFField xRes =
        new TIFFField(X_RES_TAG, TIFFField.TIFF_RATIONAL, 1, new long[][] {resolution});
    TIFFField yRes =
        new TIFFField(Y_RES_TAG, TIFFField.TIFF_RATIONAL, 1, new long[][] {resolution});
    TIFFEncodeParam tep = new TIFFEncodeParam();
    tep.setExtraFields(new TIFFField[] {xRes, yRes});
    JAI.create("Encode", img, output, "TIFF", tep);
    output.close();
  }