當前位置: 首頁>>代碼示例>>C#>>正文


C# Color.GetBrightness方法代碼示例

本文整理匯總了C#中Color.GetBrightness方法的典型用法代碼示例。如果您正苦於以下問題:C# Color.GetBrightness方法的具體用法?C# Color.GetBrightness怎麽用?C# Color.GetBrightness使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Color的用法示例。


在下文中一共展示了Color.GetBrightness方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SimilarColors

 private static bool SimilarColors(Color colorOne, Color colorTwo)
 {
     if (Math.Abs(colorOne.GetHue()-colorTwo.GetHue()) <= 36)
     {
         //Console.WriteLine("Hue");
         return true;
     }
     if (Math.Abs(colorOne.GetBrightness()-colorTwo.GetBrightness()) <= .1)
     {
         //Console.WriteLine("Hue");
         return true;
     }
     if (Math.Abs(colorOne.GetSaturation()-colorTwo.GetSaturation()) <= .1)
     {
         //Console.WriteLine("Hue");
         return true;
     }
     return false;
 }
開發者ID:dicknarby,項目名稱:HomeMonitor,代碼行數:19,代碼來源:ImageChecker.cs

示例2: UpdateHsb

        private void UpdateHsb(Color value) {
            Hue = (int)value.GetHue();

            var brightness = value.GetBrightness();
            Brightness = (int)(brightness * 100);

            var saturation = value.GetSaturation();
            Saturation = (int)(saturation * 100);

            UpdateThumbPosition();
        }
開發者ID:gro-ove,項目名稱:actools,代碼行數:11,代碼來源:ColorPickerPanel.cs

示例3: ToSurface

        public static unsafe void ToSurface(this Texture2D image, TextSurface surface, Color[] cachedColorArray, bool blockMode = false)
        {
            int imageWidth = image.Width;
            int imageHeight = image.Height;
            image.GetData<Color>(cachedColorArray);

            SurfaceEditor editor = new SurfaceEditor(surface);
            editor.Clear();
            global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) =>
            //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) =>
                for (int w = 0; w < imageWidth / surface.Font.Size.X; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    float allR = 0;
                    float allG = 0;
                    float allB = 0;

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            Color color = cachedColorArray[cY * imageWidth + cX];

                            allR += color.R;
                            allG += color.G;
                            allB += color.B;
                        }
                    }

                    byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y));

                    var newColor = new Color(sr, sg, sb);

                    float sbri = newColor.GetBrightness() * 255;

                    if (blockMode)
                    {
                        if (sbri > 204)
                            editor.SetGlyph(w, h, 219, newColor); //█
                        else if (sbri > 152)
                            editor.SetGlyph(w, h, 178, newColor); //▓
                        else if (sbri > 100)
                            editor.SetGlyph(w, h, 177, newColor); //▒
                        else if (sbri > 48)
                            editor.SetGlyph(w, h, 176, newColor); //░
                    }
                    else
                    {
                        if (sbri > 230)
                            editor.SetGlyph(w, h, (int)'#', newColor);
                        else if (sbri > 207)
                            editor.SetGlyph(w, h, (int)'&', newColor);
                        else if (sbri > 184)
                            editor.SetGlyph(w, h, (int)'$', newColor);
                        else if (sbri > 161)
                            editor.SetGlyph(w, h, (int)'X', newColor);
                        else if (sbri > 138)
                            editor.SetGlyph(w, h, (int)'x', newColor);
                        else if (sbri > 115)
                            editor.SetGlyph(w, h, (int)'=', newColor);
                        else if (sbri > 92)
                            editor.SetGlyph(w, h, (int)'+', newColor);
                        else if (sbri > 69)
                            editor.SetGlyph(w, h, (int)';', newColor);
                        else if (sbri > 46)
                            editor.SetGlyph(w, h, (int)':', newColor);
                        else if (sbri > 23)
                            editor.SetGlyph(w, h, (int)'.', newColor);
                    }
                }
            }
            );
        }
開發者ID:Thraka,項目名稱:SadConsole,代碼行數:82,代碼來源:TextureExtensions.cs

示例4: HSLColor

 public HSLColor(Color color)
 {
     Hue = color.GetHue();
     Saturation = color.GetSaturation();
     Lightness = color.GetBrightness();
 }
開發者ID:Thraka,項目名稱:SadConsoleEditor,代碼行數:6,代碼來源:HSLColor.cs


注:本文中的Color.GetBrightness方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。