Application des traitements de valeurs rvb (rgb)

Description

Comment extraire les composantes Rouge Vert et Bleu d'une variable ENTIER LONG, faire l'inverse et tout ceci dans une application de calcul d'un dégradé a 4 couelurs, mais le code a été prévu pour que ceci soit tout a fait variable, vous pouvez enlever ou rajouter des couleurs en vous aidant des commentaires.

Source / Exemple :


'  *** Lightness1024! ProgrammatO le 3/4/1 programme d'operations RVB ***

Private c() As Long
Private r() As Integer
Private v() As Integer
Private b() As Integer
Private nb As Integer

Private Sub Command1_Click()

' si vous voulez rajouter des couleurs,
' mettez des boutons dans l'interface
' graphique et copiez cette sub
' de la meme maniere a chaque fois
' (bien sur il faut adapter les numeros)

  CommonDialog1.ShowColor
  c(1) = CommonDialog1.Color
  Text1.BackColor = c(1)
End Sub

Private Sub Command2_Click()
  CommonDialog1.ShowColor
  c(2) = CommonDialog1.Color
  Text2.BackColor = c(2)
End Sub

Private Sub Command3_Click()
  Dim rap As Single
  Dim a As Integer
  
  For x = 1 To nb
    r(x) = CByte(c(x) And &HFF&)
  Next
  For x = 1 To nb
    v(x) = CByte((c(x) \ 256) And &HFF&)
  Next
  For x = 1 To nb
    b(x) = CByte((c(x) \ 65536) And &HFF&)
  Next
  For j = 1 To nb - 1
    taye = Picture1.Width
    For a = (j - 1) * taye / (nb - 1) To j * taye / (nb - 1)
      rap = (a - ((j - 1) * taye / (nb - 1))) / (taye / (nb - 1))
      
      ' ici en rap est un rapport il varie
      ' entre 0 et 1, c'est la que vous
      ' pouvez utiliser les pourcentages !
      
      Picture1.Line (a, 0)-(a, Picture1.Height), RGB(r(j) + (r(j + 1) - r(j)) * rap, v(j) + (v(j + 1) - v(j)) * rap, b(j) + (b(j + 1) - b(j)) * rap)
    Next
  Next
End Sub

Private Sub Command4_Click()
  CommonDialog1.ShowColor
  c(4) = CommonDialog1.Color
  Text3.BackColor = c(4)
End Sub

Private Sub Command5_Click()
  rrp = Text4.BackColor
  r1 = rrp And &HFF&
  v1 = (rrp \ 256) And &HFF&
  b1 = (rrp \ 65536) And &HFF&
  truc1 = Hex(r1 * 65536 + v1 * 256 + b1)
  If Len(truc1) < 6 Then truc1 = String$(6 - Len(truc1), 48) + truc1
  Text5.Text = Chr$(34) + "#" & truc1 + Chr$(34)
End Sub

Private Sub Command6_Click()
  CommonDialog1.ShowColor
  Text4.BackColor = CommonDialog1.Color
End Sub

Private Sub Command7_Click()
  CommonDialog1.ShowColor
  c(3) = CommonDialog1.Color
  Text6.BackColor = c(3)
End Sub

Private Sub Form_Load()
  
  nb = 4   'changez ce nombre par le nombre de couleurs utilisés !!!
  
  ReDim c(nb)
  ReDim r(nb)
  ReDim v(nb)
  ReDim b(nb)
End Sub

Private Sub Form_Resize()
  If Form1.ScaleWidth <= 712 Then Form1.Width = 712 * Screen.TwipsPerPixelX
  If Form1.ScaleHeight <= 260 Then Form1.Height = 260 * Screen.TwipsPerPixelY
  Picture1.Height = Form1.ScaleHeight - (216 + 15)
  Picture1.Width = Form1.ScaleWidth - (15)
End Sub

Conclusion :


il est possible d'utiliser aussi ce code pour trouver une valeur intermediaire entre une couleur et une autre pour faire un mélange, et bien sur cela de manière quantitative (20% d'une couleur avec 80% de l'autre!)
le calcul est indiqué par un commentaire.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.