Const KOUDO = &h1
Const MEIDO = &h2
'a,b,cの最大値を戻す
Function max(a,b,c)
If a > b Then max = a Else max = b
If max < c Then max = c
End Function
'a,b,cの最小値を戻す
Function min(a,b,c)
If a < b Then min = a Else min = b
If min > c Then min = c
End Function
'RGBをモノクロにしてRGB値で返す(c=1,明度、c=2,光度 c=3のとき、平均)
Function RGB24ToMonochro(rgb As DWord, c As Long) As DWord
Dim R As Byte, G As Byte, B As Byte
R = rgb And &hFF
G = (rgb >> 8) And &hFF
B = (rgb >> 16) And &hFF
Select Case c
Case MEIDO
rgb = 0.5 * (max(R,G,B) + min(R,G,B))
Case KOUDO
rgb = 0.21 * R + 0.72 * G + 0.07 * B
Case Else
rgb = (R + G + B) / 3
End Select
RGB24ToMonochro = RGB(rgb, rgb, rgb)
End Function
'RGB階調反転してRGB値で返す
Function RGB24NegaPosi(rgb As DWord) As DWord
Dim R As Byte, G As Byte, B As Byte
R = rgb And &hFF
G = (rgb >> 8) And &hFF
B = (rgb >> 16) And &hFF
RGB24NegaPosi = RGB(255-R, 255-G, 255-B)
End Function