Public Shared Function SetNumToColor(ByVal pixelColor As System.Drawing.Color, ByVal number As Byte) As System.Drawing.Color
Dim colorNumber As Byte = GetNumFromColor(pixelColor)
If number < 8 And number >= 0 Then
'Find which components need toggling
colorNumber = colorNumber Xor number
'Colornumber is now a number from 0 to 7, where the bits equal to 1
'represent the color components that need to toggle their last bit, with red in the
'least significant bit and blue in the most significant bit
'To get the Red bit, we rightshift 0 times and then bitwise AND this number with 1.
'To get the Green bit, we rightshift 1 times and then bitwise AND this number with 1.
'To get the Blue bit, we rightshift 2 times and then bitwise AND this number with 1.
Return System.Drawing.Color.FromArgb( _
pixelColor.A, _
SetColorComponent(pixelColor.R, CBool(colorNumber >> 0 And 1)), _
SetColorComponent(pixelColor.G, CBool(colorNumber >> 1 And 1)), _
SetColorComponent(pixelColor.B, CBool(colorNumber >> 2 And 1)) _
)
Else
Return pixelColor
End If
End Function