Пример #1
21
        public BitmapImage Render(uint clearColor, uint setColor)
        {
            int resultWidth = Data.Count;
            int maximum = Data.Max();
            double divisor = 1;
            int resultHeight = maximum;

            if (resultHeight > 1024)
            {
                while (resultHeight > 1024)
                {
                    resultHeight /= 2;
                    divisor *= 2;
                }
            }

            BitmapImage result = new BitmapImage(resultWidth, resultHeight);
            result.SetAllPixels(clearColor);

            for (int i = 0; i < Data.Count; i++)
            {
                int element = Data[i];
                int adjustedHeight = (element > 1) ? (int)(element / divisor) : 1;

                int y = result.Height - 1;
                while (adjustedHeight > 0)
                {
                    result[i, y] = setColor;
                    y--;
                    adjustedHeight--;
                }
            }

            return result;
        }