public DefaultPaintingSession(IPaintAlgorithm paintingAlgorithm)
        {
            this.paintingAlgorithm = paintingAlgorithm;

            this.backgroundWorker.DoWork += (s, e) =>
            {
                var arguments               = (IList <object>)e.Argument;
                var rtb                     = (RenderTargetBitmap)arguments[0];
                var width                   = (int)arguments[1];
                var height                  = (int)arguments[2];
                var directoryPath           = (string)arguments[3];
                var backgroundRtb           = (RenderTargetBitmap)arguments[4];
                var backgroundDirectoryPath = (string)arguments[5];

                var    image    = new Bitmap(width, height);
                Bitmap painting = RenderTargetBitmapToBitmap(rtb);
                var    overlay  = new Bitmap(Resources.SavedImageFrame, width, height);
                using (var gr = Graphics.FromImage(image))
                {
                    gr.DrawImage(painting, new System.Drawing.Point(0, 0));
                    gr.DrawImage(overlay, new System.Drawing.Point(0, 0));
                }

                string currentTime = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss");
                string fullPath    = Path.Combine(directoryPath, currentTime + ".png");
                Directory.CreateDirectory(directoryPath);
                image.Save(fullPath, ImageFormat.Png);

                string backgroundFilePath = Path.Combine(backgroundDirectoryPath, currentTime + "_original.png");
                Directory.CreateDirectory(backgroundDirectoryPath);
                SaveRenderTargetBitmapAsPng(backgroundRtb, backgroundFilePath);
            };
        }
Пример #2
0
        public TestModePaintingSession(IPaintAlgorithm paintAlgorithm)
        {
            this.paintAlgorithm = paintAlgorithm;

            this.backgroundWorker.DoWork += (s, e) =>
            {
                var arguments = (IList <object>)e.Argument;
                var backgroundWithPainting = (RenderTargetBitmap)arguments[0];
                var background             = (RenderTargetBitmap)arguments[1];
                var parentDirectoryPath    = (string)arguments[2];

                var directoryPath = Path.Combine(parentDirectoryPath, DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"));
                Directory.CreateDirectory(directoryPath);

                // Save the background with the painting
                string backgroundWithPaintingFilePath = Path.Combine(directoryPath, "painting.png");
                DefaultPaintingSession.SaveRenderTargetBitmapAsPng(backgroundWithPainting, backgroundWithPaintingFilePath);

                // Save just the background
                string backgroundFilePath = Path.Combine(directoryPath, "background.png");
                DefaultPaintingSession.SaveRenderTargetBitmapAsPng(background, backgroundFilePath);

                // Save the raw body frame data points
                string csvSerializedSensorDataFilePath = Path.Combine(directoryPath, "sensor_data.csv");
                using (var file = new StreamWriter(csvSerializedSensorDataFilePath))
                {
                    file.WriteLine(SensorBody.GetCsvHeader());
                    foreach (var sensorBodyFrame in this.sensorRecorder.SensorData.BodyFrames)
                    {
                        string[] csvSerializedBodies = sensorBodyFrame.Bodies.Select(b => b.SerializeToCsv()).ToArray();
                        file.WriteLine(string.Join(",", csvSerializedBodies));
                    }
                }

                string jsonSerializedSensorData         = JsonConvert.SerializeObject(this.sensorRecorder.SensorData);
                string jsonSerializedSensorDataFilePath = Path.Combine(directoryPath, "sensor_data.json");
                File.WriteAllText(jsonSerializedSensorDataFilePath, jsonSerializedSensorData);
            };
        }