English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我想寫一個程式,就像Windows內建的色彩選擇器。
先從左邊的彩色圖選取一個顏色,再在右邊選擇該顏色的亮度。
假設我在左邊選了:黃色(255,255,0),則右邊會繪出由\"白\"到\"黃\"再到\"黑\"的漸層,其他顏色(像:(38,146,217))也要一樣,由\"白\"到\"該顏色\"再到\"黑\",剩下的我都會,就差這一步,請高人指點!

2006-02-25 19:02:52 · 2 個解答 · 發問者 ? 2 in 電腦與網際網路 程式設計

2 個解答

'不知道是不是您要的XD,表單置1個PictureBox
Private Declare Sub ColorRGBToHLS Lib "shlwapi" (ByVal clrRGB As Long, pwHue As Integer, pwLuminance As Integer, pwSaturation As Integer)
Private Declare Function ColorHLSToRGB Lib "shlwapi" (ByVal pwHue As Long, ByVal pwLuminance As Long, ByVal pwSaturation As Long) As Long

Private Sub Form_Load()
AutoRedraw = True
Dim R As Byte, G As Byte, B As Byte
R = 255: G = 255: B = 255
X = 1000: Y = 1000: cr = 800: pi = 3.1415926
With Picture1
  .ScaleMode = vbPixels: .Height = 3615: .Width = 285: .Left = 2340: .Top = 60
End With

For I = 1 To 120
  For J = 2 To 1 Step -1
    DrawWidth = J
     xr = Sin(pi * I / 180) * cr
    yr = -Cos(pi * I / 180) * cr
    ix = Sin(pi * I / 180) * (cr - 250)
    iy = -Cos(pi * I / 180) * (cr - 250)
    Line (X + ix, Y - iy)-(X + xr, Y - yr), RGB(Int(R * (120 - I) / 120), Int(G * I / 120), 0)
    xg = Sin(pi * (I + 120) / 180) * cr
     yg = -Cos(pi * (I + 120) / 180) * cr
     ix = Sin(pi * (I + 120) / 180) * (cr - 250)
    iy = -Cos(pi * (I + 120) / 180) * (cr - 250)
    Line (X + ix, Y - iy)-(X + xg, Y - yg), RGB(0, Int(B * (120 - I) / 120), Int(G * I / 120))
    xb = Sin(pi * (I + 240) / 180) * cr
    yb = -Cos(pi * (I + 240) / 180) * cr
    ix = Sin(pi * (I + 240) / 180) * (cr - 250)
    iy = -Cos(pi * (I + 240) / 180) * (cr - 250)
    Line (X + ix, Y - iy)-(X + xb, Y - yb), RGB(Int(R * I / 120), 0, Int(G * (120 - I) / 120))
  Next
Next
End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim I As Long, J As Long, H As Integer, S As Integer, B As Integer, C As Long, nR, nG, nB As Integer

With Picture1
  ColorRGBToHLS Point(X, Y), H, B, S
  .AutoRedraw = True
  .Cls
  B = S: S = 0
  For I = 0 To .ScaleHeight - 1
    C = ColorHLSToRGB(H, B, S)
    nR = C And 255
    nG = (C / 256) And 255
    nB = (C / 65536) And 255
    For J = 0 To .ScaleWidth - 1
      Picture1.PSet (J, I), RGB(nR, nG, nB)
    Next
    S = S + 1: B = B - 1
    If B < 0 Or S > 255 Then Exit Sub
  Next
  .AutoRedraw = False
End With
End Sub

2006-03-01 04:43:26 · answer #1 · answered by W.J.S. 7 · 0 0

其實使用一個 CommonDialog 控制項
就可以使用 Windows內建的色彩選擇器 了

CommonDialog.flags = cdlCCFullOpen
CommonDialog.ShowColor
GetColor = CommonDialog.Color
如此 GetColor 就是選取的顏色值

至於你要說的顏色層次
好像與 Windows不大一樣的說 (windows都是從黑到白,但中間顏色層次是你選的顏色)
白是 FF FF FF 也就是 BGR(255,255,255) 黑是 00 00 00
黃 00 FF FF 到 00 00 00 很簡單
B都沒變 G與R範圍 從 FF~00
如果色條長100 (ScaleHeight=100,ScaleMode=3)
每格變化就是 2.55
要貼上顏色就用 Picture.Line

2006-02-25 13:59:30 · answer #2 · answered by weilai 5 · 0 0

fedest.com, questions and answers