VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get the seperate RGB values of a Colour

by Davy Cook (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

It turns the Decimal format of a colour value (example: 16777215) into three seperate values containing the seperate Red, Green, and Blue values. (example: red = 255, green = 255, blue = 255).

Inputs
Input the colour that you wish to turn into its seperate RGB values. This should be in Decimal format.
Assumes
Just make sure to keep the types as Long (&) because using an Integer (%) causes an overflow in the Red Value.
Code Returns
Returns the Red, Green, and Blue value from a colour.
Side Effects
'None.
API Declarations
'None.

Rate Get the seperate RGB values of a Colour

Dim blue&, green&, red&, colour&
Blue& = Int(Colour& / 65536)
Green& = Int((Colour& - (65536 * Blue&)) / 256)
Red& = Colour& - (Blue& * 65536) - (Green& * 256)
'to return the colour to its original decimal format
Colour& = RGB(Red&, Green&, Blue&)

Download this snippet    Add to My Saved Code

Get the seperate RGB values of a Colour Comments

No comments have been posted about Get the seperate RGB values of a Colour. Why not be the first to post a comment about Get the seperate RGB values of a Colour.

Post your comment

Subject:
Message:
0/1000 characters