//** $File : imageConvert.js
//** $Info : Convert all present image file to a selected new one.
//** $Revision : 0.0.2
//** $Date : January 8 2005
//** $Author : Manuele Turini mt@dta.it
//** $Company : DTA srl
//** $License : This file is part of an example program for Qj. This example program may be used, distributed and modified without limitation.
//** $History :
// Basic I/O class
var sys = new System();
// Destination file format
var ext = "png";
// Integer variable used as counter
var d = 1;
// Path name of the images to be converted
var dir = "g:/Images/Some/";
// Request to the user if the source path name is correct
var choice = QMessageBox.question(0, "IMAGE CONVERTER", "Is this path name <b>" + dir + "</b> correct ?", QMessageBox.Yes, QMessageBox.No);
// If press the user press NO, select a new directory
if(choice == QMessageBox.No)
dir = QFileDialog.getExistingDirectory("/");
sys.printf("Target directory = <b>%s</b>", dir);
// Get the names of all present files in the selected directory
var fileList = sys.fileList(dir, "*.*; *.");
// Create an image class
var dil = new DIL(MainWidget());
// Convert all images to the selected format
for(c = 0; c < fileList.length(); c++)
// Check if DIL known this image format
if(DIL.isALoadableFileFormat(fileList[c]))
{
// Load the image
dil.load(dir + fileList[c]);
// Save the image with the new format
dil.save(dir + sys.changeFileExtension(fileList[c], ext));
// Print on the console the name of the source and destination file name
sys.printf("Image %4d = %s =>> %s", d++, fileList[c], sys.changeFileExtension(fileList[c], ext));
// Close the loaded image
dil.close();
}
// Delete the image class
delete dil;