|
-
Nov 20th, 2000, 04:01 PM
#1
Thread Starter
So Unbanned
I need to convert a long value of a color to the relative R G B values mathematically, since I don't know how, I leave it to this board's capible 'hands'.
Thank you,
-
Nov 20th, 2000, 04:15 PM
#2
transcendental analytic
R = Color mod 256
G = int(Color / 256) mod 256
B = int(Color / &h10000)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 20th, 2000, 04:17 PM
#3
Monday Morning Lunatic
Code:
Private Type ColourRGB
lRed As Integer
lGreen As Integer
lBlue As Integer
End Type
Private Sub Form_Load()
Dim z As ColourRGB
z = ExtractColour(RGB(&HAA, &HBB, &HCC))
Debug.Print Hex(z.lRed)
Debug.Print Hex(z.lGreen)
Debug.Print Hex(z.lBlue)
End Sub
Private Function ExtractColour(lColour As Long) As ColourRGB
Dim tempC As ColourRGB
tempC.lBlue = (lColour \ &H10000) And &HFF
tempC.lGreen = (lColour \ &H100) And &HFF
tempC.lRed = lColour And &HFF
ExtractColour = tempC
End Function
- depending on where your colour came from, you may need to swap the Red and Blue values around (endian problems).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 20th, 2000, 04:20 PM
#4
Frenzied Member
while everyone is on the subject of colors, how is it possible to save the custom colors in a choosecolor dialog box when the user creates them even if they dont select the color as they click ok?
retired member. Thanks for everything 
-
Nov 20th, 2000, 04:20 PM
#5
Frenzied Member
Use Mod
I have not checked the following, but it should be close to correct.
Code:
Dim Red As Integer
Dim Green As Integer
Dim Blue As Integer
Dim Tlong As Long
Blue = RGBvalue Mod 256 'Blue is remainder after divide by 256
Tlong = (RGBvalue - Blue)/256 'Tlong now contains Red & Blue values.
Green = Tlong Mod 256
Red = (Tlong - Green)/256
I am not sure what VB does with arithmetic using Integer & Long variables, but I think it does sensible integer arithmetic.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Nov 20th, 2000, 04:30 PM
#6
transcendental analytic
well markman, depends what choosecolor dialog box you are using?
There's also a way to get the RGB values as you know the color is stored in a long and each value represent a byte
Code:
Type LngColor
Color As Long
End Type
Type RGBColor
Red As Byte
Green As Byte
Blue As Byte
Dummy As Byte
End Type
Dim a As LngColor, b As RGBColor
a.Color = 123456
LSet b = a
With b
Debug.Print .Red
Debug.Print .Green
Debug.Print .Blue
End With
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 20th, 2000, 06:23 PM
#7
Code:
lRed = lColor Mod &H100
lGreen = Int(lColor / &H100) Mod &H100
lBlue = Int(lColor / &H10000) Mod &H100
-
Nov 20th, 2000, 09:18 PM
#8
transcendental analytic
meg, you don't need to use modulus for lblue
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|