Reputation: 7550
How can I pass an array of filenames into the following method:
public static double getFitness(int x, int y, int r, BufferedImage image);
I currently have a method which creates an array of filenames from a given directory:
//Default image directory (to convert to greyscale).
static File dir = new File("images");
//Array of original image filenames.
static File imgList[] = dir.listFiles();
public static void processGreyscale(){
if(dir.isDirectory()){
for(File img : imgList){
if(img.isFile()){
//functions are carried out here.
}
else{
//functions are carried out here.
}
}
}
}
The getFitness
method scores the fitness of an image (...BufferedImage image);
) based on the main region of interest (ROI).
What I am looking for is a way to run the getFitness
method on the array of filenames; something like this:
public static double getFitness(int x, int y, int r, fileArray)
Can this be done?
Thank you all for your great suggestions; however, I should mention that I wish to leave the method parameters the same/unchanged as the fitness function is affected (negatively) if I change the passed parameters.
Is there any way that I can run the fitness function on all files/filenames within imgList[]
?
What I'm hoping for is this:
public static double getFitness(int x, int y, int r, BufferedImage image){
use filenames stored in imgList[] to take place of 'image'
getFitness of `image`
next image name
}
Is this possible?
Upvotes: 1
Views: 197
Reputation: 4318
You can do
File fileArray[] = new File[numberOfFiles];
then specify a counter to store in the array such as counter = 0
and increment the value of counter
each time fileName is added to the array fileArray[counter] = img.getName(); counter++;
then send the array in your desired method public static double getFitness(x, y, r, fileArray);
Upvotes: 0
Reputation: 47413
Yes, it is possible.
This is the method signature:
public static double getFitness(int x, int y, int r, File[] fileArray)
And this is the calling code:
getFitness(1, 1, 1, imgList);
Upvotes: 3
Reputation: 55593
Just pass the array?
public static double getFitness(int x, int y, int r, File[] files);
Upvotes: 1