0

I have created a desktop application where I can open the same image in two internalFrames. I need to change one of those images to grayscale within the application.

My attempt to do this is shown below. When I click the button in my file menu, I need one internal frame image to be the original image and the other one to be grayscale.

GuiPanelImage(File fileName) {
     width = GuiPanelImage.WINDOW_WIDTH;

     height = GuiPanelImage.WINDOW_HEIGHT;

    try {
        BufferedImage inputImage = ImageIO.read(fileName); 

        outputImage = new BufferedImage(inputImage.getWidth(),
          inputImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
// I can replace .TYPE_INT_ARGB with .TYPE_BYTE_GRAY to convert to grayscale

        picture = new ImageIcon(fileName.getPath());

        Graphics2D g2d = ( Graphics2D) outputImage.createGraphics();

        g2d.drawImage(inputImage, 0, 0, null); 
    } 
    catch (IOException ex) {
        Logger.getLogger(GuiPanelImage.class.getName()).log(Level.SEVERE,
          null, ex);
    }             
}
Pops
  • 30,199
  • 37
  • 136
  • 151
Bashrina
  • 1
  • 1

3 Answers3

1

Why can't you just do the following?

outputImage1 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
outputImage2 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Vincent van der Weele
  • 12,927
  • 1
  • 33
  • 61
  • Yes MR Torgamus i did that part before, just the way you have posted these syntax ; but didnt work just becuse i got no idea how to call outputImage2 in loadActionPerformed code here is the code – Bashrina Mar 29 '13 at 17:01
1

PictureFrame illustrates how to display a picture in a JInternalFrame.

internal frame

ColorConvertOp is illustrated here and compared to a disabled image here.

gray icons

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

try raster functions for scanning the input and create and output directory for it