Example #1
0
        public bool TakeScreenshot(IEngine engine)
        {
//            throw new NotImplementedException();

            var fileName = GenerateScreenshotName().Path;

            if (active == false)
            {
                return(active);
            }

            try
            {
                var pixels = engine.displayChip.pixels;

                var displaySize = engine.gameChip.Display();


                var visibleWidth  = displaySize.X;
                var visibleHeight = displaySize.Y;
                var width         = engine.displayChip.width;


                // Need to crop the image
                var newPixels = new Color[visibleWidth * visibleHeight];

                var totalPixels    = pixels.Length;
                var newTotalPixels = newPixels.Length;

                var index = 0;

                for (var i = 0; i < totalPixels; i++)
                {
                    var col = i % width;
                    if (col < visibleWidth && index < newTotalPixels)
                    {
                        newPixels[index] = pixels[i];
                        index++;
                    }
                }

                // We need to do this manually since the exporter could be active and we don't want to break it for a screenshot
                var tmpExporter = new ImageExporter(fileName, imageExporter, newPixels, visibleWidth, visibleHeight);
                tmpExporter.CalculateSteps();

                // Manually step through the exporter
                while (tmpExporter.completed == false)
                {
                    tmpExporter.NextStep();
                }


                workspace.SaveExporterFiles(new Dictionary <string, byte[]> {
                    { tmpExporter.fileName, tmpExporter.bytes }
                });

                return(true);
            }
            catch
            {
//                Console.WriteLine("Take Screenshot Error:\n"+e.Message);
                // TODO throw some kind of error?
                return(false);
            }
        }