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 7594055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:19:07+00:00 2026-05-30T21:19:07+00:00

I am experiencing problems when running some code that I am developing. It should

  • 0

I am experiencing problems when running some code that I am developing.

It should work as such:

For all images within directory (x)

    Read image
    Convert to greyscale
    Save to new directory (y)

    For all images within new directory (y)
        Read image
        Convert to binary
        Save to new directory (z)
    End for

End for

I have 300 images at present and so far all images are successfully converted to greyscale and saved to a new directory. However, the binary conversion is where the problems occur as it appears to not detect any images in the new directory and only appears to work if [image] files already exist within the directory before the code is executed.

Therefore, the following is what actually happens:

All files in directory (x) are read
All files in directory (x) are converted to greyscale and saved to new directory (y)
All files in directory (y) are read
It appears that directory (y) is empty (but, in fact, contains 300 greyscale images)
Program ends

However, when I run the program a second time, either with the 300 greyscale images or even a single images, the images in directory (y) are successfully converted into binary; it appears to only work if there are pre-existing images in the directory and not whilst the newly-converted-to-greyscale images are being created on-the-fly.

The method is called as follows:

public static void processFiles(){
    processGreyscale();
    System.out.println("Greyscale image conversion complete.\n");
    processBinary();
    System.out.println("Binary image conversion complete.\n");
}

I have even tried adding a time-delay between method calls to allow for the system to update itself in order to detect the newly-created [greyscale] images (in directory (y)), but this does not make any difference and the images are only recognised and converted to binary when two conditions are satisfied:

  1. There are images present in directory (y)
  2. The code is run for a second time or if there are any [image] files within the directory before the code is first executed.

Is there a way to do this so that the newly-generated greyscale images are detectable as soon as they have been created and then converted to binary?

Many thanks.

UPDATE: My code for converting to greyscale is as follows:

    try{
        //Read in original image. 
        BufferedImage inputImg = ImageIO.read(image);

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

        //New images to draw to.
        BufferedImage bimg = null;
        BufferedImage img = inputImg;

        //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 binary (output) image.   
        String fileName = "greyscale_" + image.getName();
        File file = new File("test_images\\Greyscale\\" + fileName);
        ImageIO.write(bimg, "jpg", file);
    }
    catch (Exception e){
                  System.out.println(e);
    }

How would I modify this to add the flush() and/or close() functions?

UPDATE: I have also created a line which prints after each successful conversion and the only feedback I have from the binary method is: java.lang.NullPointerException (BINARY) test_images\Greyscale\desktop.ini: processed successfully. Binary image conversion complete. whereas it should say: (BINARY) images\298.jpg: processed successfully..

Is there any reason for this? I don’t understand why the desktop.ini file is read/processed?

  • 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-30T21:19:08+00:00Added an answer on May 30, 2026 at 9:19 pm

    I have discovered what the problem was and have now resolved the issue.

    Thanks to those of you who provided useful suggestions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing some problems with breaking my code to reusable parts using templates and
I'm debugging a service that's experiencing some problems on start-up. To aid me in
I've been experiencing segfaults when running some C++ code. I've isolated the problem to
I am using the following code, but experiencing some problems: mDb.beginTransaction(); String updateQuery =Query
I'm experiencing two intermittent problems with Silverlight 3.0, running on Windows 7 with Visual
I am experiencing some performance problems when creating a very simple Python HTTP server.
I am experiencing some strange problems with NHibernate and the usage of proxy items
I have been developing some computer vision tools with openCV, but every time that
We are experiencing some slowdowns on our web-app deployed on a Tomcat 5.5.17 running
I'm experiencing some problems when using the default date:difference EXSLT template, provided at http://www.exslt.org/date/functions/difference/index.html

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.