C#: Forming colours based on integers

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Benny the Bear
Posts: 146
Joined: Sat Oct 27, 2007 2:44 am UTC
Location: Melbourne, Australia
Contact:

C#: Forming colours based on integers

Postby Benny the Bear » Sun Feb 24, 2008 8:23 am UTC

Hi, I'm making a program where an image is drawn based off text found in a text file. I'm encountering an issue where I have the numbers that, in an RGB format, make up a colour. My question is, how do I convert these values into a colour? I thought something such as

Code: Select all

Color clrExample = new Color();
clrExample.R = 00;


would do the trick, but the Color.R only returns, not sets, the value.

Once I have the correct colour object, I'm fine.

Note: I say 'colour' as per the Australian/UK spelling, but in C# 'color' is used, as per the American spelling. Just so we're on track.

Any help is appreciated.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: C#: Forming colours based on integers

Postby Sc4Freak » Sun Feb 24, 2008 8:59 am UTC

Have you checked the documentation?

According to MSDN:
System.Drawing.Color
MSDN wrote:Named colors are represented by using the properties of the Color structure. For more information about these colors, see Colors by Name in the MSDN Library. To determine the alpha, red, green, or blue component of a color, use the A, R, G, or B property, respectively.

You can create a custom color by using one of the FromArgb methods.


Color.FromArgb Method
MSDN wrote:Creates a Color structure from the four 8-bit ARGB components (alpha, red, green, and blue) values.

User avatar
Benny the Bear
Posts: 146
Joined: Sat Oct 27, 2007 2:44 am UTC
Location: Melbourne, Australia
Contact:

Re: C#: Forming colours based on integers

Postby Benny the Bear » Sun Feb 24, 2008 9:37 am UTC

I didn't think to simple type 'Color.' and see what came up. I did it with a color object, but not the actual class itself.

Well, it worked. Cheers :) .


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 12 guests