DR00ME Posted February 25, 2004 Posted February 25, 2004 Hi, I'm using API- function: Private Declare Function ColorHLSToRGB Lib "SHLWAPI.DLL" _ (ByVal wHue As Integer, ByVal wLuminance As Integer, ByVal wSaturation As Integer) As Long How do I convert Long to RGB so I could take the R,G and B component out of it. Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Moderators Robby Posted February 25, 2004 Moderators Posted February 25, 2004 This is something that Squirm came up with a couple of years ago... dim nColor as long = yourValue nRed = nColor And 255 nGreen = (nColor \ 256) And 255 nBlue = (nColor \ 65536) And 255 Quote Visit...Bassic Software
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 (edited) R=252, G=254, B=214 converted to HSB is H=63, S=0,952381, B=0,9176471 'This is a fact I know (I got the values from the same pixel) (pixel.R pixel.G pixel.B) and (pixel.GetHue, pixel.GetSaturation, pixel.GetBrightness) B is sometimes called V (value) or L(luminance) I guess... anyway. Now here is my function and some code: Private Declare Function ColorHLSToRGB Lib "SHLWAPI.DLL" _ (ByVal wHue As Integer, ByVal wLuminance As Integer, ByVal wSaturation As Integer) As Long Dim nColor as Long Dim nRed,nGreen,nBlue as Integer nColor = ColorHLSToRGB(63, 0.9176471, 0.952381) nRed = nColor And 255 nGreen = (nColor / 256) And 255 nBlue = (nColor / 65536) And 255 Me.Text = CStr(nRed) + " " + CStr(nGreen) + " " + CStr(nBlue) Why it is giving me a wrong result(1 1 1) instead of (252 254 214) please help this is doing my head in. Edited February 25, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 Anyone ? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 sorry, sometimes I get too frustrated lol... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
bri189a Posted February 25, 2004 Posted February 25, 2004 what is the value of nColor after calling that external function? Quote
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 I think I'm not gonna use that bloody API. Gonna make my own function which actually works properly = gives you proper Byte values. Thanks everyone who participated on this thread. btw. bri189a sometimes I want to do same as your avatar. Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
bri189a Posted February 25, 2004 Posted February 25, 2004 Thanks... I'm currently doing that now with my db problem... I guess the results from the API weren't what you expected? :) Quote
Moderators Robby Posted February 25, 2004 Moderators Posted February 25, 2004 What is the value of nColor after ColorHLSToRGB() ?? Quote Visit...Bassic Software
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 The long value is exactly: 579820650753 eh... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
*Experts* Bucky Posted February 25, 2004 *Experts* Posted February 25, 2004 In case you were wondering, the problem lies in this line: nColor = ColorHLSToRGB(63, 0.9176471, 0.952381) Since the API only accepts integers, the last two parameters were rounded off. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 Private Declare Function ColorHLSToRGB Lib "SHLWAPI.DLL" _ (ByVal wHue As Single, ByVal wLuminance As Single, ByVal wSaturation As Single) As Long As you can see I changed the types to singles... the result changed but it is still a wrong result. Now the long is: 1005025044970 According to this formula: nRed = nColor And 255 nGreen = (nColor / 256) And 255 nBlue = (nColor / 65536) And 255 it gives result of: 234 42 41 (RGB) = wrong answer. Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Administrators PlausiblyDamp Posted February 25, 2004 Administrators Posted February 25, 2004 Changing the declaration to single rather than integer doesn't alter the fact that the under-lying API still uses integers. You are just slightly changing the rounding error. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 (edited) I think ColorRGBToHLS is using standard values ? like saturation min=0 max=1 and brightness min=0 max=1... so they are single not integer... I dont know from where I got the failure API structure but there shouldnt be integers as input. The under-lying API is using long or singles. Maybe I should try Longs too. ???????????????? Edited February 25, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Administrators PlausiblyDamp Posted February 25, 2004 Administrators Posted February 25, 2004 Nope, the api doesn't accept floating point values - just checked in MSDN and they accept 16-bit unsigned integers and returns a 32-bit integer so I suppose the proper declaration is Private Declare Function ColorHLSToRGB Lib "SHLWAPI.DLL" _ (ByVal wHue As Short, ByVal wLuminance As Short, ByVal wSaturation As Short) As integer but as Bucky said - the 2nd and 3rd parameters are being rounded off. Where are you getting the values for the last two parameters from? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
DR00ME Posted February 25, 2004 Author Posted February 25, 2004 (edited) Oh I see, well do you know the min and max values for saturation and luminance for input ? Like what standard it is using ? I guess it doesnt mean Short max value is e.g. saturation max value ? This is a bit confusing now. pls don't tell me it is using max values like 239,240,240 = MS Paint (hue,sat,lum) .... oh dear...this is something I didn't want to know....:) but then again it doesnt make any sense why the API is using short as Sat. and Lum. input instead of Byte (min. 0 max 255) grrr :/ (63, 0.9176471, 0.952381) I got those values using .hue .getsaturation and .getbrightness from a specific pixel.... and I cant convert them to right RGB values without using my own function... ???? Edited February 25, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Recommended Posts