用RGB()函数只要设置三基色各自的分量就可以返回一个LONG,那么有没有一个函数能设置一个LONG型值,而返回三个RGB分量呢?

解决方案 »

  1.   

    '取出红色的数值
     lngRed = Int(RGBColor / 65536)
     RGBColor = RGBColor - lngRed * 65536
     '取出绿色的数值
     lngGreen = Int(RGBColor / 256)
     '剩下的是蓝色的数值
     lngBlue = RGBColor - lngGreen * 256
      

  2.   

    Public Function LongToRGB(Value As Long, _
        Optional chooseDelimiter As String = ",") As StringDim Blue As Double, Green As Double, Red As Double
    Dim BlueS As Double, GreenS As Double, RGBs As String    Blue = Fix((Value / 256) / 256)
        BlueS = (Blue * 256) * 256
        Green = Fix((Value - BlueS) / 256)
        GreenS = Green * 256
        Red = Fix(Value - BlueS - GreenS)
        RGBs = (Red & chooseDelimiter & Green & chooseDelimiter & Blue)
        LongToRGB = RGBs
        
    End Function
      

  3.   

    同意楼上的两位
    其实VB中没有现成的函数来处理它
    你只要把一个数值作相应的运算,就可以得到三个颜色的long值。
      

  4.   

    '在模块中声明
    'RGB值的结构
    Public Type RGBValue
        Red As Long
        Green As Long
        Blue As Long
    End TypePublic Function GetRGB(RGBColor As Long) As RGBValue
        '取出红色的数值
         GetRGB.Blue = Int(RGBColor / 65536)
         RGBColor = RGBColor - GetRGB.Blue * 65536
         '取出绿色的数值
         GetRGB.Green = Int(RGBColor / 256)
         '剩下的是蓝色的数值
         GetRGB.Red = RGBColor - GetRGB.Green * 256
     End Function'调用方法
    Dim typRGB As RGBValue
    typRGB = GetRGB(CLng(strTemp))Debug.Print typRGB.Red
    Debug.Print typRGB.Green
    Debug.Print typRGB.Blue '
    Debug.Print " "
      

  5.   

    补充说明:上面给出的调用方法中的strTemp是一个String类型的数字数据