We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Convert uint to color

ruanlab123 asked
Medium Priority
Last Modified: 2012-06-27

I use the Crystal 10 RDC dll to make changes to a report at runtime.  All the color properties is of type uint.
So I've got this method to convert a color to a uint value, and it works fine.

public static uint colorToUint(Color clr)
            return (uint)(clr.R + (clr.G << 8) + (clr.B << 16));

But now I want to write a method to convert a uint value into a color's RGB.  

Can anybody help me please.

Watch Question

Top Expert 2006
Hello ruanlab123,

you could look at this post from Tim Wilson
source: http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/msg/4184603f0ffd2578?hl=en&
private uint RGB(Color color)
  // Format the value of color - 0x00bbggrr
  return ((uint) (((uint) (color.R) | ((uint) (color.G) << 8)) | (((uint) (color.B)) << 16)));

private Color UnRGB(int color)
  return Color.FromArgb(color & 0xFF, (color & 0xFF00) >> 8, (color & 0xFF0000) >> 16);

hope this helps a bit

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks it works fine!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.