public static void Konvertierung(String inputDir, String outputDir, String tiff_file, float x_scale, float y_scale, int grad, long x_res, long y_res) {
try {
// Übergabe-Parameter einlesen und Variablen definieren
String inputPfad = inputDir + tiff_file;
String outputPfad = outputDir + tiff_file;
PlanarImage image_in;
PlanarImage image_out;
System.out.println(inputPfad);
System.out.println(outputPfad);
// Grafik einlesen
File f_input = new File(inputPfad);
FileSeekableStream fss = new FileSeekableStream(inputPfad);
if ( f_input.exists() && f_input.canRead() ) {
image_in = JAI.create("stream", fss);
OutputStream out = new FileOutputStream(outputPfad);
// Grafik skalieren
ParameterBlock pb1 = new ParameterBlock();
pb1.addSource(image_in);
pb1.add(x_scale); // x-scale factor
pb1.add(y_scale); // y-scale factor
pb1.add(0.0F); // x-translate
pb1.add(0.0F); // y-translate
pb1.add(new InterpolationNearest());
image_out = JAI.create("scale", pb1);
// Grafik drehen
ParameterBlock pb2 = new ParameterBlock();
float y = (float)image_in.getHeight()/2;
float x = (float)image_in.getWidth()/2;
float angle = (float)Math.toRadians(grad);
pb2.addSource(image_out);
pb2.add(x);
pb2.add(y);
pb2.add(angle);
pb2.add(new InterpolationNearest());
image_out = JAI.create("rotate", pb2);
// Druckauflösung der Grafik festlegen und Kompression bestimmen
TIFFEncodeParam tep = new TIFFEncodeParam();
TIFFField[] extras = new TIFFField[3];
extras[0] = new TIFFField(282,TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{x_res,(long)1},{(long)0 ,(long)0}});
extras[1] = new TIFFField(283,TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{y_res,(long)1},{(long)0 ,(long)0}});
extras[2] = new TIFFField(296, TIFFField.TIFF_SHORT, 1, (Object) new char[] {2});
tep.setExtraFields(extras);
tep.setCompression(TIFFEncodeParam.COMPRESSION_GROUP3_2D);
JAI.create("encode",image_out, out, "tiff", tep);
// sämtliche Objekte schließen und Aufräumarbeiten ausführen
out.close();
fss.close();
image_in.dispose();
image_out.dispose();
System.gc();
// Input-Datei löschen
// f_input.delete();
}
else {
System.out.println("Quelldatei " + tiff_file + " existiert nicht oder kann nicht gelesen werden !");
}
}
catch (Exception e) {
System.err.println("Fehler: " + e.getMessage());
}
}