x404.co.uk
http://x404.co.uk/forum/

More programming stuff...
http://x404.co.uk/forum/viewtopic.php?f=3&t=4880
Page 1 of 1

Author:  Fogmeister [ Fri Dec 11, 2009 9:31 am ]
Post subject:  More programming stuff...

Hi Guys,

I'm trying to do some work with colours (RGB values, etc...).

The control that I have returns an integer and I have found a function that converts the integer into separate red, green and blue values.

But it isn't working.

The function I found is...

input colourvalue.

redvalue = colourvalue MOD 256.
greenvalue = (colourvalue / 256) MOD 256.
bluevalue = (colourvalue / 256 / 256) MOD 256.

This seems to almost work but not quite.

I have put the same formulae into Excel to check it is working correctly and it does.

For instance, when I click a cyan like colour RGB(0,255,255). The int returned is 16776960. Excel turns this into 0,255,255 but my program thyinks it is 0,255,0.

Simililarly when I select white, Excel says it is 255,255,255 but my program thinks it is 255,0,0.

Not sure what could be going on here.

Any ideas?!

Author:  Fogmeister [ Fri Dec 11, 2009 9:34 am ]
Post subject:  Re: More programming stuff...

Woohoo!

Truncate is your freind!

Stupid thing

Author:  EddArmitage [ Fri Dec 11, 2009 9:35 am ]
Post subject:  Re: More programming stuff...

I'd check the double-division for the blue one and add some extra brackets to be safe/clear.

Author:  Fogmeister [ Fri Dec 11, 2009 9:42 am ]
Post subject:  Re: More programming stuff...

EddArmitage wrote:
I'd check the double-division for the blue one and add some extra brackets to be safe/clear.

That's what I thought is might be but it's down to rounding. The program was being too clever and turning 255.56738239... into 256. I needed to truncate instead.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/