PC Review


Reply
Thread Tools Rate Thread

Convert RGB to Red/Green/Blue component

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      6th Apr 2009
I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      6th Apr 2009
Barb,

You can adapt the following code:

Dim R As Long
Dim G As Long
Dim B As Long
Dim RGBLong As Long
R = &H10
G = &H20
B = &H30
RGBLong = RGB(R, G, B)
Debug.Print Hex(RGBLong)
R = RGBLong And &HFF
G = (RGBLong And &HFF00&) \ &H100&
B = (RGBLong And &HFF0000) \ &H10000
Debug.Print Hex(R), Hex(G), Hex(B)

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Mon, 6 Apr 2009 08:04:15 -0700, Barb Reinhardt
<(E-Mail Removed)> wrote:

>I've seen this somewhere, but can't find it now. Can someone direct me to
>the formulas to convert to R/G/B components.
>
>Thanks,
>Barb Reinhardt

 
Reply With Quote
 
egun
Guest
Posts: n/a
 
      6th Apr 2009
Here's one version:

Public Function LongToRGB(theColor As Long, iRed As Integer, iGreen As
Integer, iBlue As Integer) As Boolean
'
Dim lColor As Long
lColor = theColor 'work long
iRed = lColor Mod 256 'get red component
iGreen = (lColor \ 256) Mod 256 'get green component
iBlue = (lColor \ 256 \ 256) Mod 256 'get blue component
'
LongToRGB = True
End Function


HTH,

Eric

"Barb Reinhardt" wrote:

> I've seen this somewhere, but can't find it now. Can someone direct me to
> the formulas to convert to R/G/B components.
>
> Thanks,
> Barb Reinhardt

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      6th Apr 2009
Here is one more method...

Dim Red As Long
Dim Green As Long
Dim Blue As Long
Dim HexVal As String

HexVal = Hex(rgbValue)
Red = CLng("&H" & Right(HexVal, 2))
Green = CLng("&H" & Mid(HexVal, 3, 2))
Blue = CLng("&H" & Left(HexVal, 2))

Debug.Print Red, Green, Blue

--
Rick (MVP - Excel)


"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:C7C535C5-0DF1-4B20-989A-(E-Mail Removed)...
> I've seen this somewhere, but can't find it now. Can someone direct me to
> the formulas to convert to R/G/B components.
>
> Thanks,
> Barb Reinhardt


 
Reply With Quote
 
David
Guest
Posts: n/a
 
      6th Apr 2009
Note that when using HEX values that Microsoft handles the HEX values in
reverse order.

All others (HTML, VB RGB Functions, etc.) = R,G,B

Microsoft Hex value is ---> B,G,R




"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:C7C535C5-0DF1-4B20-989A-(E-Mail Removed)...
> I've seen this somewhere, but can't find it now. Can someone direct me to
> the formulas to convert to R/G/B components.
>
> Thanks,
> Barb Reinhardt



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Blue to Green and Back to Green Loadmaster Microsoft Excel Misc 5 15th Aug 2008 12:33 AM
Silver, Blue or Green? KGB-911 Windows XP 56 29th Apr 2005 11:48 AM
hue sat lum red green blue =?Utf-8?B?Q29sb3JibGluZEJydWlu?= Windows XP General 4 18th Jan 2005 09:35 PM
green to blue =?Utf-8?B?b2xsZQ==?= Windows XP Basics 2 18th Sep 2004 01:37 PM
Blue/Green Screen Dan Windows XP MovieMaker 1 22nd Dec 2003 03:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:14 AM.