Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determin 256 Colour values

Status
Not open for further replies.

emergencyplan

Technical User
Aug 19, 2003
34
GB
Hello,

I have a program that currently displays Digital Elevation Models (DEM) in twenty colours, ranging from dark blue (low elevation RGB(0,0,255) to red (high elevation rgb(255,0,0)).

I now wish to display the DEM in 234 (or 255 replacing black to show the lowest elevations) colours between these to extremes (dark blue - red). Previously I hard-coded the values for the twenty colours, but I was hoping to use code to generate the colour values this time round.

Any ideas?? Many thanks.

Laurence

 
Loop? Decrement the Blue value and/or Increment the Red value for each iteration? You can "see" something similar in the following procedure.

Code:
Private Sub Form_Timer()

    Dim MyColor As Long
    Dim ClrRed As Long
    Dim ClrGrn As Long
    Dim ClrBlu As Long

    MyColor = Me.cmdColor_Test.ForeColor

    Debug.Print MyColor

    ClrRed = MyColor And vbRed
'    ClrGrn = (MyColor And vbGreen) / vbRed + 1
    ClrGrn = 0
    ClrBlu = (MyColor And vbBlue) / (vbRed + vbGreen + 1)

    If (ClrRed > 10) Then
        ClrRed = ClrRed - 10
     Else
        ClrBlu = ClrBlu + 10
    End If

    If (ClrBlu > 245) Then
        ClrRed = vbRed
        ClrBlu = 0
    End If
    
    MyColor = RGB(ClrRed, ClrGrn, ClrBlu)
    Me.cmdColor_Test.ForeColor = MyColor
    Me.Refresh

End Sub

Of course this is just a (somewhat slow and tortured) example, and it runs through many more than 255 seperate colors, but the concept could be modified to generate most any specific color set to place in an array, or to just retrieve a specific color value based on the seperats RGB components.





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top