Skip to content

Instantly share code, notes, and snippets.

@7m4mon
Created November 19, 2016 05:03
Show Gist options
  • Save 7m4mon/d0edd9fa6d229165981d407f2254f559 to your computer and use it in GitHub Desktop.
Save 7m4mon/d0edd9fa6d229165981d407f2254f559 to your computer and use it in GitHub Desktop.
' Color を引数にとってHSVの値をダブル型の配列(3)として返す
' 2016/11/19 https://ja.wikipedia.org/wiki/HLS%E8%89%B2%E7%A9%BA%E9%96%93 を参考に白を近似色で選ぶように変更
Function GetHSB(pColor As Color) As Double()
Dim hsbH As Double
Dim hsbS As Double
Dim hsbB As Double
With pColor
Dim rgbArray As Double() = {.R, .G, .B}
hsbH = .GetHue()
hsbH = hsbH / 360 '0~1に直す
'hsbS = .GetSaturation()
'hsbB = .GetBrightness() 'RGBの最大値にした方が結果に近いようだ。
hsbS = (rgbArray.Max - rgbArray.Min) '/ (1 - Abs(.Max + .Min - 1)) '円柱モデルだと黒が無くなってしまうので双円錐モデルを採用
hsbB = (rgbArray.Max) ' + rgbArray.Min) / 2 '平均を取る方だと.GetBrightness()と同じ結果になる
End With
Dim hsbArray() As Double = {hsbH, hsbS, hsbB}
Return hsbArray
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment