当前位置: 首页>>代码示例>>C#>>正文


C# Color.GetBrightness方法代码示例

本文整理汇总了C#中System.Drawing.Color.GetBrightness方法的典型用法代码示例。如果您正苦于以下问题:C# Color.GetBrightness方法的具体用法?C# Color.GetBrightness怎么用?C# Color.GetBrightness使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Color的用法示例。


在下文中一共展示了Color.GetBrightness方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatColor

		private static String FormatColor(String format, Color arg)
		{
			if (String.IsNullOrWhiteSpace(format))
			{
				return arg.ToString();
			}

			var numberFormatInfo =
				new NumberFormatInfo
				{
					NumberDecimalDigits = 1,
					PercentDecimalDigits = 0,
					PercentNegativePattern = 1,
					PercentPositivePattern = 1
				};
			switch (format)
			{
				case "hex":
					{
						return String.Format(numberFormatInfo, "#{0:x2}{1:x2}{2:x2}", arg.R, arg.G, arg.B);
					}
				case "HEX":
					{
						return String.Format(numberFormatInfo, "#{0:X2}{1:X2}{2:X2}", arg.R, arg.G, arg.B);
					}
				case "rgb":
					{
						return String.Format(numberFormatInfo, "rgb({0}, {1}, {2})", arg.R, arg.G, arg.B);
					}
				case "rgb%":
					{
						return String.Format(numberFormatInfo, "rgb({0:P}, {1:P}, {2:P})", arg.R / 255d, arg.G / 255d, arg.B / 255d);
					}
				case "rgba":
					{
						return String.Format(numberFormatInfo, "rgba({0}, {1}, {2}, {3:0.#})", arg.R, arg.G, arg.B, arg.A / 255d);
					}
				case "rgba%":
					{
						return String.Format(numberFormatInfo, "rgba({0:P}, {1:P}, {2:P}, {3:0.#})", arg.R / 255d, arg.G / 255d, arg.B / 255d, arg.A / 255d);
					}
				case "hsl":
					{
						return String.Format(numberFormatInfo, "hsl({0:F0}, {1:P}, {2:P})", arg.GetHue(), arg.GetSaturation(), arg.GetBrightness());
					}
				case "hsla":
					{
						return String.Format(numberFormatInfo, "hsla({0:F0}, {1:P}, {2:P}, {3:0.#})", arg.GetHue(), arg.GetSaturation(), arg.GetBrightness(), arg.A / 255d);
					}
				default:
					{
						throw new FormatException(String.Format("Invalid format specified: \"{0}\".", format));
					}
			}
		}
开发者ID:Happy-Ferret,项目名称:dotgecko,代码行数:55,代码来源:CssColorFormatInfo.cs

示例2: GetConsoleColor

		internal static ConsoleColor GetConsoleColor(Color color) {
			if (color.GetSaturation() < 0.5) {
				// we have a grayish color
				switch ((int)(color.GetBrightness()*3.5)) {
				case 0:
					return ConsoleColor.Black;
				case 1:
					return ConsoleColor.DarkGray;
				case 2:
					return ConsoleColor.Gray;
				default:
					return ConsoleColor.White;
				}
			}
			int hue = (int)Math.Round(color.GetHue()/60, MidpointRounding.AwayFromZero);
			if (color.GetBrightness() < 0.4) {
				// dark color
				switch (hue) {
				case 1:
					return ConsoleColor.DarkYellow;
				case 2:
					return ConsoleColor.DarkGreen;
				case 3:
					return ConsoleColor.DarkCyan;
				case 4:
					return ConsoleColor.DarkBlue;
				case 5:
					return ConsoleColor.DarkMagenta;
				default:
					return ConsoleColor.DarkRed;
				}
			}
			// bright color
			switch (hue) {
			case 1:
				return ConsoleColor.Yellow;
			case 2:
				return ConsoleColor.Green;
			case 3:
				return ConsoleColor.Cyan;
			case 4:
				return ConsoleColor.Blue;
			case 5:
				return ConsoleColor.Magenta;
			default:
				return ConsoleColor.Red;
			}
		}
开发者ID:avonwyss,项目名称:bsn-goldparser,代码行数:48,代码来源:ConsoleTextWriter.cs

示例3: binarization

        private void binarization(Bitmap imgSrc)
        {
           
            int px; double br;
            double threshold = 0.5;
            
            for (int row = 0; row < height - 1; row++)
            {
                for (int col = 0; col < width - 1; col++)
                {
                    pixel = imgSrc.GetPixel(col, row);
                    px = pixel.ToArgb();
                    br = pixel.GetBrightness();
                    if (pixel.GetBrightness() < threshold)
                    {

                        GreyImage[col, row] = 0;

                    }
                    else
                    {

                        GreyImage[col, row] = 1;
                    }

                }
            }
        }
开发者ID:sunitbelbase,项目名称:OCR-radon-transformation,代码行数:28,代码来源:Seperation.cs

示例4: HSLColor

 public HSLColor(Color color)
 {
     RGB = color;
     H = (byte)((color.GetHue() / 360.0f) * 255);
     S = (byte)(color.GetSaturation() * 255);
     L = (byte)(color.GetBrightness() * 255);
 }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:7,代码来源:HSLColor.cs

示例5: Saturation

        public static ColorSlider Saturation(VisualDirection direction, float knobWidth, float minVisualLength, 
			Color color, Reaction<float> changed)
        {
            return new ColorSlider (direction, knobWidth, minVisualLength, 0f, 1f, color.GetSaturation (),
                new [] { Color.White, VisualHelpers.ColorFromHSB (color.GetHue (), 1f, color.GetBrightness ()) },
                changed);
        }
开发者ID:johtela,项目名称:Compose3D,代码行数:7,代码来源:ColorSlider.cs

示例6: IsOldStar

 public bool IsOldStar(Color pixelColor)
 {
     return ((pixelColor.GetHue() >= 150) &&
         (pixelColor.GetHue() <= 258) &&
         (pixelColor.GetSaturation() >= 0.10) &&
         (pixelColor.GetBrightness() <= 0.90));
 }
开发者ID:lanedraex,项目名称:multithread_study,代码行数:7,代码来源:Form1.cs

示例7: GetColorComponents

        public static void GetColorComponents(ColorModel colorModel, Color color, out Single componentA, out Single componentB, out Single componentC)
        {
            componentA = 0.0f;
            componentB = 0.0f;
            componentC = 0.0f;

            switch (colorModel)
            {
                case ColorModel.RedGreenBlue:
                    componentA = color.R;
                    componentB = color.G;
                    componentC = color.B;
                    break;

                case ColorModel.HueSaturationBrightness:
                    componentA = color.GetHue();
                    componentB = color.GetSaturation();
                    componentC = color.GetBrightness();
                    break;

                case ColorModel.LabColorSpace:
                    RGBtoLab(color.R, color.G, color.B, out componentA, out componentB, out componentC);
                    break;

                case ColorModel.XYZ:
                    RGBtoXYZ(color.R, color.G, color.B, out componentA, out componentB, out componentC);
                    break;
            }
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:29,代码来源:ColorModelHelper.cs

示例8: GetFullContrastColor

 private static Color GetFullContrastColor(Color color)
 {
     return
         color.GetBrightness() > BrightnessThreshold
             ? Color.Black
             : Color.White;
 }
开发者ID:Carbenium,项目名称:gitextensions,代码行数:7,代码来源:EdgeColor.cs

示例9: getColour

 private void getColour()
 {
     int r, g, b = 0;
     DialogResult result = GUI.colorDialog.ShowDialog();
     if (result != DialogResult.Cancel)
     {
         color = GUI.colorDialog.Color;
         r = color.R;
         g = color.G;
         b = color.B;
         GUI.txtColourRGBdecimal.Text = r + ", " + g + ", " + b;
         GUI.txtColourRGB.Text = String.Format("{0:X2}", r) + String.Format("{0:X2}", g) + String.Format("{0:X2}", b);
         GUI.txtColourRGBcss.Text = "#" + String.Format("{0:X2}", r) + String.Format("{0:X2}", g) + String.Format("{0:X2}", b);
         GUI.txtColourRdec.Text = r.ToString();
         GUI.txtColourGdec.Text = g.ToString();
         GUI.txtColourBdec.Text = b.ToString();
         GUI.txtColourRhex.Text = String.Format("{0:X2}", r);
         GUI.txtColourGhex.Text = String.Format("{0:X2}", g);
         GUI.txtColourBhex.Text = String.Format("{0:X2}", b);
         GUI.lblColourSample.BackColor = color;
         GUI.lblColourSample.Image = null;
         // RGB ->HSL conversion
         decimal h = decimal.Round(((decimal)(color.GetHue() / 360) * 240), MidpointRounding.AwayFromZero);
         decimal s = decimal.Round(((decimal)color.GetSaturation() * 240), MidpointRounding.AwayFromZero);
         decimal l = decimal.Round(((decimal)color.GetBrightness() * 240), MidpointRounding.AwayFromZero);
         GUI.txtColourH.Text = h.ToString();
         GUI.txtColourS.Text = s.ToString();
         GUI.txtColourL.Text = l.ToString();
     }
 }
开发者ID:kippy76,项目名称:Desktop_Utilities_1_2,代码行数:30,代码来源:Colour.cs

示例10: ColorHSL

 /// <summary>
 /// Initialize a new instance of the ColorHSL class.
 /// </summary>
 /// <param name="c">Initialize from an existing Color.</param>
 public ColorHSL(Color c)
 {
     // Initialize from the color instance
     _hue = c.GetHue() / 360f;
     _saturation = c.GetBrightness();
     _luminance = c.GetSaturation();
 }
开发者ID:Cocotteseb,项目名称:Krypton,代码行数:11,代码来源:HSL.cs

示例11: HslColor

 public HslColor(Color color)
 {
   _alpha = color.A;
   _hue = color.GetHue();
   _saturation = color.GetSaturation();
   _lightness = color.GetBrightness();
   _isEmpty = false;
 }
开发者ID:FrankGITDeveloper,项目名称:Landsknecht_GreenScreen,代码行数:8,代码来源:HslColor.cs

示例12: CalculateColorDifference

        private static double CalculateColorDifference(Color lhs, Color rhs)
        {
            double hue = lhs.GetHue() - rhs.GetHue();
            double brightness = lhs.GetBrightness() - rhs.GetBrightness();
            double saturation = lhs.GetSaturation() - rhs.GetSaturation();

            return Math.Sqrt(hue * hue + brightness * brightness + saturation * saturation);
        }
开发者ID:mkkim1129,项目名称:ASmallGoodThing,代码行数:8,代码来源:AsScriptControl.xaml.cs

示例13: DistinctColorInfo

        /// <summary>
        /// Initializes a new instance of the <see cref="DistinctColorInfo"/> struct.
        /// </summary>
        public DistinctColorInfo(Color color)
        {
            Color = color.ToArgb();
            Count = 1;

            Hue = Convert.ToInt32(color.GetHue()*Factor);
            Saturation = Convert.ToInt32(color.GetSaturation()*Factor);
            Brightness = Convert.ToInt32(color.GetBrightness()*Factor);
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:12,代码来源:DistinctColorInfo.cs

示例14: AddColor

 /// <summary>
 /// Method to add/sum two colors.
 /// </summary>
 /// <param name="hitColor"></param>
 /// <param name="tintColor"></param>
 /// <returns></returns>
 public static Color AddColor(Color hitColor, Color tintColor)
 {
     float brightness = tintColor.GetBrightness();
     var result = Color.FromArgb(
             (int)Cap((int)((1 - brightness) * hitColor.R) + CapMin(tintColor.R - 20, 0) * 255 / 205, 255),
             (int)Cap((int)((1 - brightness) * hitColor.G) + CapMin(tintColor.G - 20, 0) * 255 / 205, 255),
             (int)Cap((int)((1 - brightness) * hitColor.B) + CapMin(tintColor.B - 20, 0) * 255 / 205, 255)
         );
     return result;
 }
开发者ID:gy814,项目名称:GraviRayTraceSharp,代码行数:16,代码来源:ColorHelper.cs

示例15: CompareColorByBrightness

		int CompareColorByBrightness(Color c1, Color c2)
		{
			float h1 = c1.GetBrightness();
			float h2 = c2.GetBrightness();
			if (h1 < h2)
				return -1;
			if (h1 > h2)
				return 1;
			return 0;
		}
开发者ID:jtorjo,项目名称:logwizard,代码行数:10,代码来源:ColorTable.cs


注:本文中的System.Drawing.Color.GetBrightness方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。