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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:16:19+00:00 2026-06-10T19:16:19+00:00

I am writing a program to perform various operations on an image using the

  • 0

I am writing a program to perform various operations on an image using the following code:

import java.awt.Desktop;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;

public class BrightnessContrast {
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        int i, j, choice = 1;
        String imgName;
        boolean flag = true;

        String imagePath = "images/test.jpg";
        BufferedImage myImage = ImageIO.read(new File(imagePath));
        int height = myImage.getHeight();
        int width = myImage.getWidth();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final BufferedImage greyImage = new BufferedImage(width, height,BufferedImage.TYPE_BYTE_GRAY);
        Graphics grp = greyImage.getGraphics();
        grp.drawImage(myImage, 0, 0, null);
        File f2 = new File("images/BrightnessContrastTestInput.jpg");
        try {
            ImageIO.write(greyImage, "JPG", f2);
        } catch (IOException x) {
            x.printStackTrace();
        }

        while (flag == true) {
            System.out
                    .println(" 1.Brightness \n 2.Contrast \n 3.EXIT!");
            choice = Integer.parseInt(br.readLine());

            switch (choice) {
            case 1:
                //increase brightness

            case 2:
                //increase contrast
            case 3:
                flag = false;
                break;
            default:
                System.out.println("Invalid Option. Please try again.");
                break;
            }
        }
    }

    public static void ImageOperation(BufferedImage greyImage) {

        WritableRaster  myRaster = greyImage.getRaster();

        for (j = 0; j < greyImage.getHeight(); j++) {
            for (i = 0; i < greyImage.getWidth(); i++) {
                //some logic to increase contrast and brightness 
            }
        }

        File f = new File("images/"+imgName);
        try {
            ImageIO.write(greyImage, "JPG", f);
        } catch (IOException x) {
            x.printStackTrace();
        }
    }
    }

}

All the manipulations are done on the writable raster object myRaster in ImageOperation method, myRaster is created using a BufferedImage object greyImage.

Now, in the first run when i (let’s say) increase contrast of an image by a certain factor, it gives a proper result, in the second time if i apply the exact same amount of contrast it does that operation on the previously enhanced image, not the original one, thus, in the second go it gives me a higher contrast.

my question is that, is the BufferedImage object greyImage getting updated each time i increase contrast on the myRaster?

  • 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-06-10T19:16:21+00:00Added an answer on June 10, 2026 at 7:16 pm

    Looking at the source for BufferedImage, getRaster() returns a reference to the underlying raster object within the buffered image. So if you change the raster, you have effectively changed the image.

    You might want to make a copy of the original image and then operate on the copy. This should preserve the original.

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

Sidebar

Related Questions

I'm writing a genetic program to perform symbolic regression on a formula. I'm using
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing an image processing program to perform real time processing of video frames.
I am writing a script that calls another java program, to perform some tasks.
I'm writing a program in C++ to perform a simulation of particular system. For
I am currently writing a program using Weka that builds a model (using one
I am writing a program to do some image processing. I am working with
I'm trying to perform morphology using Magick++ from a c++ program that I am
I am writing a program that runs through pintools, to perform dynamic taint analysis
I'm writing a simple program in Python 2.7 using pycURL library to submit file

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.