Product : Engine, Version : 4.0.1.1018, ArticleID : 41018064

HowTo : RGB colors

Article41018064
TypeHowTo
ProductEngine
Version4.0.1.1018
Date Added4/9/2003
Submitted bySheena Konikkara
Keywords

Subject

RGB colors

Summary

Is there any function that can be used to convert RGB colors to 255 colors?

Solution

See the code (Visual Basic 6.0) code:
    Note: colors with index 0, 7 and 255 is better to not be changed.

Private Sub Command1_Click()
Dim ColorsP(255, 3) As Variant
Dim I   As Integer
Dim Red, Green, Blue
For I = 0 To 255
    ColorsP(I, 0) = VDPro.VdColorIndexToRGB(I)
    Red = ColorsP(I, 0) Mod 256
    Green = ((ColorsP(I, 0) - Red) / 256) Mod 256
    Blue = ((ColorsP(I, 0) - Green * 256 - Red) / 65536) Mod 256   
    ColorsP(I, 1) = Red
    ColorsP(I, 2) = Green
    ColorsP(I, 3) = Blue
    ' I make the COLOR,RED,GREEN,BLUE table
Next I
End Sub

Private Sub Command2_Click()
Dim Red, Green, Blue, Color
    VDPro.ActiveDocument.ActiveColor = VdColorRed    
    VDPro.CommandAction.CmdLine Array(Array(0, 0, 0), Array(5, 5, 5))
    Red = 200
    Green = 255
    Blue = 19
    Color = Blue * 65536 + Green * 256 + Red
    MsgBox "Change VdColorRed color to " & CStr(Color)
    
    VDPro.RGBToVdColorIndex Red, Green, Blue, 1
    VDPro.Redraw
End Sub