-1

I am able to use the method to revert the image back to its original state after applying filters that are built into my program ONCE, after that whenever I press the JButton linked to the restore method it does nothing. Here is what I believe to be all the relevant code:

private OFImage originalImage;
private OFImage currentImage;

private void openFile()
    {
        int returnVal = fileChooser.showOpenDialog(frame);

        if(returnVal != JFileChooser.APPROVE_OPTION) {
            return;  // cancelled
        }
        File selectedFile = fileChooser.getSelectedFile();
        currentImage = ImageFileManager.loadImage(selectedFile);
        originalImage = ImageFileManager.loadImage(selectedFile);

        if(currentImage == null) {   // image file was not a valid image
            JOptionPane.showMessageDialog(frame,
                    "The file was not in a recognized image file format.",
                    "Image Load Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        imagePanel.setImage(currentImage);
        setButtonsEnabled(true);
        showFilename(selectedFile.getPath());
        showStatus("File loaded.");
        updateCropToolbar(currentImage.getWidth(), currentImage.getHeight());
        frame.pack();
    }

private void restoreOriginal() {
        OFImage restore = originalImage;
        currentImage = restore;
        imagePanel.setImage(currentImage);
        updateCropToolbar(currentImage.getWidth(), currentImage.getHeight());
        showStatus("File restored.");
        frame.pack();
    }

Apologies, this is my first question so if formatting is poor or I am blatantly missing crucial information, let me know. I just cannot for the life of me work out why originalImage is not being set after it has already set once.

  • 1
    *"Here is what I believe to be all the relevant code:"* 1) For better help sooner, [edit] to add a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). – Andrew Thompson Mar 24 '20 at 04:39
  • @AndrewThompson thanks for the feedback, I have shortened it as best as I could. – Frrraserrr Mar 24 '20 at 23:48

1 Answers1

0

I changed my code so that instead of changing the image it freshly loads the image.

I made selectedFile a field that I set during the loading of the image and changed my method as follows:

private void restoreOriginal() {
        currentImage = ImageFileManager.loadImage(selectedFile);
        imagePanel.setImage(currentImage);
        updateCropToolbar(currentImage.getWidth(), currentImage.getHeight());
        showStatus("File restored.");
        frame.pack();
    }