I have created a desktop application where I can open the same image in two internalFrame
s. 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);
}
}