Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:12:19+00:00 2026-05-28T22:12:19+00:00

Is it possible to feed an array of image names into code which converts

  • 0

Is it possible to feed an array of image names into code which converts images to greyscale?

I am able to convert an image into greyscale by using this code:

public static void makeGrey() { 
try{
//Read in original image. 
BufferedImage image = ImageIO.read(new File("images\\012.jpg"));

//Obtain width and height of image.
double image_width = image.getWidth();
double image_height = image.getHeight();

BufferedImage bimg = null;
BufferedImage img = image;

//Draw the new image.      
bimg = new BufferedImage((int)image_width, (int)image_height, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D gg = bimg.createGraphics();
gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);

//Save new greyscale (output) image.
String temp = "_inverted";
File fi = new File("images\\" + temp + ".jpg");
ImageIO.write(bimg, "jpg", fi);
}
catch (Exception e){
              System.out.println(e);
}
}

However, this code only works on a single file at a time and I would like to know how to go about getting it to work through all files located in the images directory?

I have created an array which goes through the images directory and stores the names of all of the files and I would like to know how to pass these filenames into my makeGrey() method?

    static File dir = new File("images");
    static File imgList[] = dir.listFiles();

    public static void listFiles(String imageName) {

        if(dir.isDirectory()){
            for(File img : imgList){
                if(img.isFile()){
                MakeGrey.makeGrey();
            }
        }
    }

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:12:20+00:00Added an answer on May 28, 2026 at 10:12 pm

    Your makeGray() method should look like this:

    public static void makeGrey(File image) { 
    try{
        //Read in original image. 
        BufferedImage inputImage = ImageIO.read(image);
        ...
        ...
        //Save new greyscale (output) image. (Or you'll rewrite same image all the time...)
        File fi = new File("images\\inverted_" + image.getName() 
        ...
        ...
    

    and other part of the code should call it like this:

    static File dir = new File("images");
    static File imgList[] = dir.listFiles();
    
    public static void listFiles(String imageName) {
    
        if(dir.isDirectory()){
            for(File img : imgList){
                if(img.isFile()){
                MakeGrey.makeGrey(img);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Converting XML to JSON using Python? I am importing an XML feed
Is it possible to create a valid RSS feed using RABL ? Or are
Is it at all possible to combine two different query results into one feed
Possible Duplicates: (PHP5) Extracting a title tag and RSS feed address from HTML using
Is it possible to have a portable area feed into a ASP.Net MVC 3
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: How do you send email from a Java app using Gmail? How
Is it possible to feed a single Master Page Content Placeholder from multiple areas
Is that even possible ? Lets say that the code has a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.