【问题标题】:Get transparency of a bufferedimage获取缓冲图像的透明度
【发布时间】:2013-05-17 01:53:28
【问题描述】:

我想更改图像的所有蓝色。我用这个代码来修改它。

int i, j, red, green, blue;
        for(i = 0; i < 64; i++){
            for(j = 0; j < 64; j++){
                Color c = new Color(brImage.getRGB(i, j));
                red = c.getRed();
                green = c.getGreen();
                blue = c.getBlue();
                int rgb = new Color(0, 255, 0).getRGB();
                if(red == 0 && green == 0 && blue == 178){
                    brImage.setRGB(i, j, rgb);
                }
            }
        }

问题是它会改变所有透明区域的颜色,而不仅仅是蓝色区域。我该如何解决这个问题?

【问题讨论】:

    标签: java image colors rgb bufferedimage


    【解决方案1】:

    您需要包含当前像素的 alpha 级别...

    int i, j, red, green, blue, alpha;
    for(i = 0; i < 64; i++){
        for(j = 0; j < 64; j++){
            Color c = new Color(brImage.getRGB(i, j));
            red = c.getRed();
            green = c.getGreen();
            blue = c.getBlue();
            alpha = c.getAlpha(); // include me...
            int rgb = new Color(0, 255, 0, alpha).getRGB();
            if(red == 0 && green == 0 && blue == 178){
                brImage.setRGB(i, j, rgb);
            }
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2016-02-27
    相关资源
    最近更新 更多