一 概述

        前提:

Java实现根据分量计算rgb值,并分离rgb分量_百度知道 (baidu.com)icon-default.png?t=M1L8https://zhidao.baidu.com/question/2079674468685898308.html

二 计算RGB的值

        代码实例:

import java.awt.*;

public class RGB {

    public static void main(String[] args) {
        rgb();
    }

    public static void rgb(){
        // 方法1: 一个整数转换成 Color ,然后获得r g b的值 ,优点:好记忆
        int rgb = 33324442;
        Color c = new Color(rgb);
        int r = c.getRed();
        int g = c.getGreen();
        int b = c.getBlue();
        System.out.println(c);
        System.out.println("红=" + r + "\t绿=" + g + "\t蓝=" + b);

        // 方法2: 对整数直接进行计算得到rgb值
        int rgb2 = 33324442;
        int r1 = (rgb2 >> 16) & 0xFF;
        int g1 = (rgb2 >> 8) & 0xFF;
        int b1 = (rgb2 >> 0) & 0xFF;
        System.out.println("红="+r1+"\t绿="+g1+"\t="+b1);
    }
}

        结果:

        

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐