Exemplo n.º 1
0
        static unsafe UIImage DrawCells(int nfc, int cellSize, float[] data)
        {
            var width  = cellSize * nfc;
            var height = cellSize * nfc;

            UIGraphics.BeginImageContext(new CoreGraphics.CGSize(width, height));
            var maxi = Array.IndexOf(data, data.Max());

            for (var i = 0; i < nfc; i++)
            {
                var v = Math.Clamp(data[i], -1f, 1f);
                var r = v < 0 ? 255 : 0;
                var g = v >= 0 ? 255 : 0;
                UIColor.FromRGBA(r, g, 0, (byte)(255 * Math.Abs(v))).SetColor();
                UIGraphics.RectFill(new CoreGraphics.CGRect(i * cellSize, 0, cellSize, cellSize));
                if (i == maxi)
                {
                    i.ToString().DrawString(new CoreGraphics.CGPoint(i * cellSize, cellSize), UIFont.SystemFontOfSize(cellSize));
                }
                UIColor.FromWhiteAlpha(1.0f, 0.5f).SetColor();
                UIGraphics.RectFrame(new CoreGraphics.CGRect(i * cellSize, 0, cellSize, cellSize));
            }
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(image);
        }