Returns a new color using floating-point RGB values ranging from 0f to 1f. - CSharp System.Drawing

CSharp examples for System.Drawing:Color RGB

Description

Returns a new color using floating-point RGB values ranging from 0f to 1f.

Demo Code


using Microsoft.Xna.Framework;
using System;//  w w w .  j a va2s .c o  m

public class Main{
        /// <summary>
        /// Returns a new color using floating-point RGB values ranging from 0f to 1f.
        /// </summary>
        public static Color FromRgb(float r, float g, float b)
        {
            return new Color(new Vector3(r, g, b));
        }
        /// <summary>
        /// Returns a new color using integral RGB values ranging from 0 to 255.
        /// </summary>
        public static Color FromRgb(int r, int g, int b)
        {
            const float maxValue = byte.MaxValue - 1;
            return FromRgb(r / maxValue,
                           g / maxValue,
                           b / maxValue);
        }
}

Related Tutorials