Convert uint to color

Posted on 2006-04-04
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.

Question by:ruanlab123
    LVL 44

    Accepted Solution

    Hello ruanlab123,

    you could look at this post from Tim Wilson
    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
    LVL 1

    Author Comment

    Thanks it works fine!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now