我创建了一个桌面应用程序,可以在两个 internalFrame
中打开相同的图像。我需要在应用程序中将其中一张图像更改为灰度。
我的尝试如下所示。当我单击文件菜单中的按钮时,我需要一张内部帧图像作为原始图像,另一张为灰度图像。
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);
}
}
最佳答案
为什么你不能执行以下操作?
outputImage1 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
outputImage2 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
关于java - 在两个内部帧中打开图像,将其中一个更改为灰度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15705053/