Exemple #1
0
        //point[] seq
        public static Bitmap ToBitmap(GestureData[] sequence)
        {
            if (sequence.Length == 0)
                return null;

            int xmax = (int)sequence.Max(x => x.HandR.X);
            int xmin = (int)sequence.Min(x => x.HandR.X);

            int ymax = (int)sequence.Max(x => x.HandR.Y);
            int ymin = (int)sequence.Min(x => x.HandR.Y);

            int width = xmax - xmin;
            int height = ymax - ymin;

            Bitmap bmp = new Bitmap(width + 16, height + 16);

            Graphics g = Graphics.FromImage(bmp);

            for (int i = 1; i < sequence.Length; i++)
            {
                int x = (int)sequence[i].HandR.X - xmin;
                int y = (int)sequence[i].HandR.Y - ymin;
                int p = (int)Accord.Math.Tools.Scale(0, sequence.Length, 0, 255, i);

                int prevX = (int)sequence[i - 1].HandR.X - xmin;
                int prevY = (int)sequence[i - 1].HandR.Y - ymin;

                using (Brush brush = new SolidBrush(Color.FromArgb(255 - p, 0, p)))
                using (Pen pen = new Pen(brush, 16))
                {
                    pen.StartCap = LineCap.Round;
                    pen.EndCap = LineCap.Round;
                    g.DrawLine(pen, prevX, prevY, x, y);
                }
            }

            return bmp;
        }