Algorithm to Switch Between RGB and HSB Color Values

后端 未结 6 653
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 08:18

I read the article Algorithm to Switch Between RGB and HSB Color Values

Type RGBColor
     Red As Byte
     Green As Byte
     Blue As Byte
End Type

Type HS         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 08:24

    The conversion from RGB to HSB should be rather easy using the Color structure:

    Function RGBToHSB(rgb As RGBColor) As HSBColor
      Dim c As Color = Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue)
      RGBToHSB.Hue = c.GetHue()
      RGBToHSB.Saturation = c.GetSaturation()
      RGBToHSB.Brightness = c.GetBrightness()
    End Function
    

    It doesn't support the reverse, though.

提交回复
热议问题