|
-
Oct 15th, 2006, 10:00 AM
#1
Thread Starter
G&G Moderator
Color Values
Howdy all,
This may actually be more of a maths question so move it if need be. I'm wanting to know if anyone could provide me with an example of comparing two color values, at high speed. For example, say I have a Color Table, which has 20 colors in it. I want to get the value of a color, and check it against this table. If it comes close to another color in the table within a certain margin of error, then just change that color to the one in the table. If it doesn't, keep its color and add it to the table.
I'm stumped as to how I would go about this, so any suggestions would be nice 
TIA,
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Oct 15th, 2006, 02:21 PM
#2
Hyperactive Member
Re: Color Values
perhaps this will get you started-
i just pounded this out online, so no guarantees, but you should be able to get the basic idea from this...
VB Code:
Option Explicit
Private Type Cols
r As Long
g As Long
b As Long
End Type
Dim colA As Cols
Dim colB As Cols
Private Sub form_load()
colA = longToRgb(Form1.BackColor)
colB = longToRgb(Text1.BackColor)
If CompareCols(colA, colB) = True Then MsgBox "Colors roughly match" Else MsgBox "colors too far apart to match"
End Sub
Private Function longToRgb(ByVal colLong As Long) As Cols
longToRgb.r = CLng((colLong And &HFF))
longToRgb.g = CLng(((colLong \ &H100&) And &HFF&))
longToRgb.b = CLng(((colLong \ &H10000) And &HFF&))
End Function
Private Function CompareCols(col1 As Cols, col2 As Cols) As Boolean
If col1.r < col2.r + 5 And col1.r > col2.r - 6 Then
If col1.g < col2.g + 5 And col1.g > col2.g - 6 Then
If col1.b < col2.b + 5 And col1.b > col2.b - 6 Then
CompareCols = True ' values are within -5 or +6
End If 'b
End If 'g
End If 'r
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|