• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2610
  • Last Modified:

Convert uint to color

Hi

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.

Thanks
0
ruanlab123
Asked:
ruanlab123
1 Solution
 
bruintjeCommented:
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
bruintje
0
 
ruanlab123Author Commented:
Thanks it works fine!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now