【问题标题】:Open an image in two internalFrames, changing one to grayscale在两个 internalFrames 中打开一个图像,将一个更改为灰度
【发布时间】:2013-03-29 14:16:03
【问题描述】:

我创建了一个桌面应用程序,我可以在其中打开两个internalFrames 中的相同图像。我需要在应用程序中将其中一张图像更改为灰度。

我的尝试如下所示。当我点击文件菜单中的按钮时,我需要一张内部框架图像作为原始图像,另一张是灰度图像。

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);
    }             
}

【问题讨论】:

    标签: java swing desktop-application jinternalframe grayscale


    【解决方案1】:

    为什么你不能只做以下事情?

    outputImage1 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    outputImage2 = new BufferedImage(inputImage.getWidth(), inputImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
    

    【讨论】:

    • 是的,Torgamus 先生,我以前做过那部分,就像你发布这些语法的方式一样;但没有工作只是因为我不知道如何在 loadActionPerformed 代码中调用 outputImage2 这是代码
    【解决方案2】:

    PictureFrame 说明如何在JInternalFrame 中显示图片。

    ColorConvertOp 显示为here,并与禁用的图像here 进行比较。

    【讨论】:

      【解决方案3】:

      尝试使用光栅函数扫描输入并为其创建和输出目录

      【讨论】:

        猜你喜欢
        • 2022-08-05
        • 2016-04-15
        • 2014-12-11
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 1970-01-01
        • 2012-06-01
        • 1970-01-01
        相关资源
        最近更新 更多