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


C# Color.GetBrightness方法代码示例

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


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

示例1: GetSurface

        /// <summary>
        /// Returns a surface with the specified image rendered to it as characters.
        /// </summary>
        /// <param name="image">The image to render.</param>
        /// <returns>The surface.</returns>
        public TextSurface GetSurface(Texture2D image)
        {
            editor.Clear();

            image.GetData<Color>(pixels);

            System.Threading.Tasks.Parallel.For(0, surface.Width * surface.Height, (i) =>
            //for (int i = 0; i < surface.Width * surface.Height; i++)
            {
                int allR = 0;
                int allG = 0;
                int allB = 0;

                int min = i * fontPixels;
                int max = min + fontPixels;

                for (int pixel = min; pixel < max; pixel++)
                {
                    Color color = pixels[indexes[pixel]];

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

                // print our character
                byte sr = (byte)(allR / fontPixels);
                byte sg = (byte)(allG / fontPixels);
                byte sb = (byte)(allB / fontPixels);

                var newColor = new Color(sr, sg, sb);
                float sbri = newColor.GetBrightness() * 255;

                Point surfacePoint = surface.GetPointFromIndex(i);
                if (UseBlockMode)
                {
                    if (sbri > 204)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 219, newColor); //█
                    else if (sbri > 152)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 178, newColor); //▓
                    else if (sbri > 100)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 177, newColor); //▒
                    else if (sbri > 48)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 176, newColor); //░
                    else
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black);
                }
                else
                {
                    if (sbri > 230)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'#', newColor);
                    else if (sbri > 207)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'&', newColor);
                    else if (sbri > 184)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'$', newColor);
                    else if (sbri > 161)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'X', newColor);
                    else if (sbri > 138)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'x', newColor);
                    else if (sbri > 115)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'=', newColor);
                    else if (sbri > 92)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'+', newColor);
                    else if (sbri > 69)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)';', newColor);
                    else if (sbri > 46)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)':', newColor);
                    else if (sbri > 23)
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'.', newColor);
                    else
                        editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black);
                }
            }
            );

            return surface;
        }
开发者ID:Thraka,项目名称:SadConsole,代码行数:82,代码来源:TextureToSurfaceReader.cs


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