|
-
Mar 5th, 2001, 06:12 AM
#1
Thread Starter
Hyperactive Member
If I have a form which has a background colour of &H00C0C0C0 then it's easy to extract the RGB values. OK, but what if the colour of the form is taken from the current palette so the value is &H0800000F. How do I extract the value 15 from this ? Once I've got that I know how to get the RGB from the API but I'm no maths wizz so any help on getting the 15 from the value would be appreciated.
That's Mr Mullet to you, you mulletless wonder.
-
Mar 5th, 2001, 06:47 AM
#2
Frenzied Member
It just basically means using bitmasks and shifts. Since shifts aren't possible in VB, you have to simulate them with division. This code will get you the red, green and blue parts from a 32-bit colour value:
Code:
Red = Colour And 255
Green = Colour \ 256 And 255
Blue = Colour \ 65536 And 255
If you wanted the alpha too, it would be (Colour \ 16777216 And 255).
In case you hadn't noticed:
256 = 2^8
65536 = 2^16
16777216 = 2^24
Harry.
"From one thing, know ten thousand things."
-
Mar 5th, 2001, 06:50 AM
#3
Thread Starter
Hyperactive Member
Thanks Harry but I've all ready got the code for splitting out the RGB values. To expand upon my explanation - it's not a question of getting the colour values out, it's all about trying to lose the &H08 from the start of the palette colour number. However, VB looks at the number and thinks it's a negative value ! Help.
That's Mr Mullet to you, you mulletless wonder.
-
Mar 5th, 2001, 07:13 AM
#4
Frenzied Member
Oh... hmm well I've never come across this before since I don't use VB for graphics stuff, but perhaps you could convert it to a string, take off the &H using the Right() function, and then convert it back? A bit messy I know but I don't know how VB is treating the number if it's giving you the &H at the beginning.
I've just realised you said it was sticking &H08 in front of the number... why do you think it shouldn't do that?
Harry.
"From one thing, know ten thousand things."
-
Mar 5th, 2001, 07:40 AM
#5
Thread Starter
Hyperactive Member
It should do that, it's how it indicates that the colour is from a palette. You should then remove the 08 from the front and then convert the Hex to get the colour number. I'd come up with checking the hex string and using $ functions but there must be a matchematical approach to this. Thanks for looking at it though - it's really starting to p!ss me off.
That's Mr Mullet to you, you mulletless wonder.
-
Mar 5th, 2001, 07:57 AM
#6
Frenzied Member
Oh, weird.... I guess I'm used to working with C++ with, in this case, more straightforward data. Sorry I couldn't help more Maybe Abs() would remove the negativity? Just a last guess.
Harry.
"From one thing, know ten thousand things."
-
Mar 5th, 2001, 11:16 AM
#7
transcendental analytic
the thing is that vb uses SIGNED long's that ranges values from -2^31 to 2^31-1, not 0 to 2^32-1. To get around this problem (yeah this been annoying me some time) is to have a currency datatype and add 2^31 if the value is negative. It might also work if you use copymemory with an offset of 2 bytes by copying over the long to a byte array of 8 bytes to 4'th place and then copy it to the currency, then multiply by 10000 to avoid the decimals.
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.
-
Mar 5th, 2001, 11:21 AM
#8
transcendental analytic
just ignore what i said, you don't need the RGBA, but the components,copy them over to a byte array of 4 instead and you have each component in it's own byte, sorry about the confusion
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.
-
Mar 5th, 2001, 11:21 AM
#9
Frenzied Member
If you're going to start using CopyMemory, you might as well just copy the 8-bit red, green and blue components straight out of the colour value. Or perhaps I'm missing something that makes it more complicated.
Harry.
"From one thing, know ten thousand things."
-
Mar 5th, 2001, 11:22 AM
#10
Frenzied Member
Oh, well looks like you got there just before me
Harry.
"From one thing, know ten thousand things."
-
Mar 5th, 2001, 11:24 AM
#11
transcendental analytic
a bit slow today? hehe
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.
-
Mar 6th, 2001, 03:39 AM
#12
Thread Starter
Hyperactive Member
Cheers guys. This is what I did in the end :
Code:
lTemp = lColor Xor -2147483648#
If lTemp >= 1 Then
lColor = GetSysColor(lTemp)
End If
and that seems to do the trick. Cheers for the help.
That's Mr Mullet to you, you mulletless wonder.
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
|