java.awt.color 下面的getRGB怎么得出的是负数???本来想通过getRGB得到一个整数,在另外的一个部分在根据这个整数构件一个color,因为参数规定只能能传整数!!!color通过什么方法得到一整数????

解决方案 »

  1.   

    getRGB()返回默认 sRGB ColorModel 中表示颜色的 RGB 值。(24-31 位表示 alpha,16-23 位表示红色,8-15 位表示绿色,0-7 位表示蓝色)。 要得到具体R,G,B颜色分量得做个位移
    // Color color
    int rgb = color.getRGB();
    int r = (rgb & 16711680) >> 16;
    int g = (rgb & 65280) >> 8;
    int b = (rgb & 255);也可以直接使用Color的getRed(),getGreen(),getBlue()方法得到r,g,b.
      

  2.   

    一个整数怎么能代表3种颜色的集合
    如果只能用一个整数的话
    你看看这样可不可以
    r*10000+g*100+b*1
    参数传过去以后
    你再通过这种方式把rgb再转换出来使用
      

  3.   

      因为你在构造Color的时候,比如 Color sCol = new Color(255,0,0)
      这个时候实际上调用的是this(255,0,0,255),可以跟进去看看的,源码中是这样定义的
    public Color(int r, int g, int b) {
            this(r, g, b, 255);
        }
    public Color(int r, int g, int b, int a) {
            value = ((a & 0xFF) << 24) |
                    ((r & 0xFF) << 16) |
                    ((g & 0xFF) << 8)  |
                    ((b & 0xFF) << 0);
    testColorValueRange(r,g,b,a);
        }
    这个时候你去看看value值肯定是负数的,最高位为1,表示负数如果你希望得到正数,可以这么显示构造
    Color sCol = new Color(255,0,0,0)即可,希望有帮助