RGBからHLS形式へ変換 <TOP>
ColorRGBToHLS
RGBからhue・luminance・saturation(HLS)形式に変換
ColorHLSToRGB hue・luminance・saturation(HLS)からRGB形式に変換
'================================================================ '= RGBからHLS形式へ変換 '= (ColorRGBToHLS.bas) '================================================================ #include "Windows.bi" ' RGBからhue・luminance・saturation(HLS)形式に変換 Declare Sub Api_ColorRGBToHLS Lib "Shlwapi" Alias "ColorRGBToHLS" (ByVal clrRGB&, pwHue%, pwLuminance%, pwSaturation%) ' hue・luminance・saturation(HLS)からRGB形式に変換 Declare Function Api_ColorHLSToRGB& Lib "Shlwapi" Alias "ColorHLSToRGB" (ByVal wHue%, ByVal wLuminance%, ByVal wSaturation%) Var Shared Picture1 As Object Var Shared Picture2 As Object Var SHared Text(2) As Object Var Shared Bitmap As Object Picture1.Attach GetDlgItem("Picture1") Picture2.Attach GetDlgItem("Picture2") For i = 0 To 2 Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1))) : Text(i).SetFontSize 14 Next i BitmapObject Bitmap '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() Bitmap.LoadFile "flower.bmp" Picture1.DrawBitmap Bitmap, 0, 0 Bitmap.DeleteBitmap Picture1.SetMousePointer 3 End Sub '================================================================ '= '================================================================ Declare Sub Picture1_MouseMove edecl (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Sub Picture1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Var C As Long Var R As Long Var G As Long Var B As Long Var H As Integer 'Hue Var L As Integer 'Luminance Var S As Integer 'Saturation 'RGB値を取得 C = Picture1.GetPixel(X, Y) R = (C And &HFF) G = (C And &HFF00) / 256 B = (C And &HFF0000) / 65536 '取得したRGB値を背景色に Picture2.Cls Picture2.SetBackColor RGB(R, G, B) 'HLSに変換 Api_ColorRGBToHLS RGB(R, G, B), H, L, S '値の範囲(0〜240) Text(0).SetWindowText "色相 : " & Format$(H / 240 * 360, "###") & " °" Text(1).SetWindowText "明度 : " & Format$(L / 240 * 100, "###") & " %" Text(2).SetWindowText "彩度 : " & Format$(S / 240 * 100, "###") & " %" End Sub '================================================================ '= '================================================================ Declare Sub MainForm_QueryClose edecl () Sub MainForm_QueryClose() Picture1.SetMousePointer 0 End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End