Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

"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
Posted

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

Visit...Bassic Software
Posted (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 by DR00ME

"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

Posted
Anyone ?

"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

Posted
sorry, sometimes I get too frustrated lol...

"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

Posted

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.

"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

Posted

The long value is exactly:

 

579820650753

 

eh...

"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*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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.

"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

Posted (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 by DR00ME

"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
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (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 by DR00ME

"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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...