This is documentation of an archived release.
For documentation on the current version, please check Knowledge Base.

Sample : Convert Images Recursively

For this example to work, you should :

  • Specify the directory containing the images (path variable)
  • Specify the source image type (“tif”)
  • Specify the target image type (“omi”)
import com.eurotronics.app.util.imageconvertor.ImageConvertor;
import com.eurotronics.tool.image.ImageWriteManager;
import com.eurotronics.tool.Files;
import java.util.Properties;
import java.io.*;
 
 
def path = "F:/scans"
 
convertImages(path,"tif","omi");
 
void convertImages(filename,from,to)
{
    File file = new File(filename);
    if (file.isDirectory())
    {
        file.list().each{ it -> convertImages(filename+File.separator+it,from,to) }
    }
    else
    {
        if (filename.toLowerCase().endsWith(from))
        {
            /* Get input and output filenames */
            def inputFile = filename;
            def outputFile = Files.replaceExtension(inputFile,"omi");
            println("Writing "+ outputFile);
            /* Prepare properties */
            Properties writeProperties = new Properties();
            writeProperties.put(ImageWriteManager.WRITE_COMPRESSION, "none");
            /* Convert */
            ImageConvertor.convertImage(inputFile,outputFile,writeProperties/*properties*/,null/*progressmonitor*/);
        }
    }
}
 
Last modified:: 2019/03/25 11:36