Search Tools Links Login

Get the seperate RGB values of a Colour


Visual Basic 6, or VB Classic

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).

Original Author: Davy Cook

Inputs

Input the colour that you wish to turn into its seperate RGB values. This should be in Decimal format.

Assumptions

Just make sure to keep the types as Long (&) because using an Integer (%) causes an overflow in the Red Value.

Returns

Returns the Red, Green, and Blue value from a colour.

Side Effects

'None.

API Declarations

'None.

Code

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&)

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 91 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.