Differenze tra le versioni di "Convertire il valore di un colore in RGBA"

Da Gambas-it.org - Wikipedia.
Riga 5: Riga 5:
 
    
 
    
 
  <FONT Color=gray>' ''Il valore del colore va considerato così composto: <FONT Color=black>alfa</font>, <FONT Color=red>rosso</font>, <FONT Color=green>verde</font>, <FONT Color=blue>blu</font>.''</font>
 
  <FONT Color=gray>' ''Il valore del colore va considerato così composto: <FONT Color=black>alfa</font>, <FONT Color=red>rosso</font>, <FONT Color=green>verde</font>, <FONT Color=blue>blu</font>.''</font>
   gt_color_to_rgba(&FF<FONT Color=red>00</font><FONT Color=green>FF</font><FONT Color=blue>00</font>&, VarPtr(r), VarPtr(g), VarPtr(b), VarPtr(a))
+
   da_colore_a_rgba(&FF<FONT Color=red>00</font><FONT Color=green>FF</font><FONT Color=blue>00</font>&, VarPtr(r), VarPtr(g), VarPtr(b), VarPtr(a))
 
      
 
      
 
   Print "Rosso: "; <FONT Color=red>r</font>
 
   Print "Rosso: "; <FONT Color=red>r</font>
Riga 15: Riga 15:
 
   
 
   
 
   
 
   
  '''Private''' Function gt_color_to_rgba(colore As Long, rosso As Pointer, verde As Pointer, blu As Pointer, alfa As Pointer)
+
  '''Private''' Function da_colore_a_rgba(colore As Long, rosso As Pointer, verde As Pointer, blu As Pointer, alfa As Pointer)
 
    
 
    
 
   Dim st As Stream
 
   Dim st As Stream

Versione delle 18:51, 16 nov 2015

Per convertire in RGBA il valore di un colore, contenente anche il canale alfa attinente alla trasparenza, possiamo adottare il calcolo contenuto nel seguente codice:

Public Sub Main()
 
 Dim r, g, b, a As Integer
 
' Il valore del colore va considerato così composto: alfa, rosso, verde, blu.
  da_colore_a_rgba(&FF00FF00&, VarPtr(r), VarPtr(g), VarPtr(b), VarPtr(a))
   
  Print "Rosso: "; r
  Print "Verde: "; g
  Print "Blu:   "; b
  Print "Alfa:  "; a
  
End


Private Function da_colore_a_rgba(colore As Long, rosso As Pointer, verde As Pointer, blu As Pointer, alfa As Pointer)
 
 Dim st As Stream
 
  st = Memory blu For Write
  Write #st, colore And &FF As Integer
  st.Close
  
  st = Memory verde For Write
  Write #st, (colore \ CInt(2 ^ 8)) And &FF As Integer
  st.Close
  
  st = Memory rosso For Write
  Write #st, (colore \ CInt(2 ^ 16)) And &FF As Integer
  st.Close
  
  st = Memory alfa For Write
  Write #st, (colore \ CInt(2 ^ 24)) And &FF As Integer
  st.Close
  
End