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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:22+00:00 2026-05-29T06:27:22+00:00

Is it possible to generate a new image name for each image that is

  • 0

Is it possible to generate a new image name for each image that is processed using the following code (I have highlighted the relevant section)?

public static void makeBinary(File image) { 
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_BINARY);
    Graphics2D gg = bimg.createGraphics();
    gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);


// ************* THIS IS WHERE I AM HAVING DIFFICULTY ***************

    //Save new binary (output) image.   
    String temp = "_inverted";
    File fi = new File("images\\" + temp + ".jpg");
    ImageIO.write(bimg, "jpg", fi);

// ******************************************************************


}
 catch (Exception e){
    System.out.println(e);
 }
}

I have 300 images, numbered 001.jpg – 300.jpg, and what I would like is for each new outputted image to be named something along the lines of, binary_001.jpg – binary_300.jpg.

The method that calls makeBinary() is located in another class and is:

public static void listFiles() {

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

    if(dir.isDirectory()){
        for(File img : imgList){
            if(img.isFile()){
                MakeBinary.makeBinary(img);
                System.out.println(img + ": processed successfully.");
            }
            else{
                System.out.println("Directory detected; skipping to next file,");
            }
        }
    }
}

How can I go about achieving this?

Many thanks.

  • 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-29T06:27:23+00:00Added an answer on May 29, 2026 at 6:27 am

    Get the filename from your File image parameter and add it to the new filename:

    String temp = image.getName() + "_inverted";
    File fi = new File("images\\" + temp + ".jpg");
    ImageIO.write(bimg, "jpg", fi);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm prototyping a chart using ASP.NET Chart Controls. I have the following code to
is it possible to generate cross-application action links using the HTML helper class? I
While it is possible to generate PowerPoint presentations automatically using Office Automation , this
If I generate a number using: $num=rand(0, 1000); , is it possible to guess
Is it possible to generate images (jpeg, png, etc) using the Microsoft Chart Controls
Is it possible to generate a alpha-numeric ID during the creation of new contact
I am using the following code in my website, for thumbnail creation: string furl
I'm using NetBeans to develop a simple image browser. I have the class ImageBrowser
Following the apparent tradition of of using this question as the basis of new
I have on my page image: @Ajax.ImageActionLink(Url.Content(~/Content/images/star-off.png), AddToFavourite, Добавить в избранное, img_add_to_favourite, null, new

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.