예제 #1
0
        public async Task ExportAsImage()
        {
            using (await _workflow.GetOrCreateVisualComponent(_componentContainerFactory)) {
                // We set an initial size for plots, because export as image command
                // will use the current size of plot control as export parameter.
                await _workflow.Plots.ResizeAsync(600, 500, 96);

                await ExecuteAndWaitForPlotsAsync(new string[] {
                    "plot(1:10)",
                });

                foreach (var ext in new string[] { "bmp", "jpg", "jpeg", "png", "tif", "tiff" })
                {
                    var outputFilePath = _testFiles.GetDestinationPath("ExportedPlot." + ext);
                    CoreShell.SaveFilePath = outputFilePath;

                    _workflow.Plots.Commands.ExportAsImage.Should().BeEnabled();
                    await _workflow.Plots.Commands.ExportAsImage.InvokeAsync();

                    File.Exists(outputFilePath).Should().BeTrue();
                    CoreShell.LastShownErrorMessage.Should().BeNullOrEmpty();

                    var image = BitmapImageFactory.Load(outputFilePath);
                    image.PixelWidth.Should().Be(600);
                    image.PixelHeight.Should().Be(500);
                    ((int)Math.Round(image.DpiX)).Should().Be(96);
                    ((int)Math.Round(image.DpiY)).Should().Be(96);
                }
            }
        }
예제 #2
0
        public async Task ExportAsImage()
        {
            await InitializeGraphicsDevice();
            await ExecuteAndWaitForPlotsAsync(new string[] {
                "plot(1:10)",
            });

            foreach (var ext in new string[] { "bmp", "jpg", "jpeg", "png", "tif", "tiff" })
            {
                var outputFilePath = _testFiles.GetDestinationPath("ExportedPlot." + ext);
                FileDialog.SaveFilePath = outputFilePath;

                var deviceVC       = _workflow.Plots.GetPlotVisualComponent(_workflow.Plots.ActiveDevice);
                var deviceCommands = new RPlotDeviceCommands(_workflow, deviceVC);

                deviceCommands.ExportAsImage.Should().BeEnabled();
                await deviceCommands.ExportAsImage.InvokeAsync();

                File.Exists(outputFilePath).Should().BeTrue();
                CoreShell.LastShownErrorMessage.Should().BeNullOrEmpty();

                var image = BitmapImageFactory.Load(outputFilePath);
                image.PixelWidth.Should().Be(600);
                image.PixelHeight.Should().Be(500);
                ((int)Math.Round(image.DpiX)).Should().Be(96);
                ((int)Math.Round(image.DpiY)).Should().Be(96);
            }
        }
        public async Task <CommandResult> InvokeAsync()
        {
            string filePath = Path.GetTempFileName();

            try {
                await InteractiveWorkflow.Plots.ExportToBitmapAsync(
                    VisualComponent.ActivePlot,
                    "bmp",
                    filePath,
                    VisualComponent.Device.PixelWidth,
                    VisualComponent.Device.PixelHeight,
                    VisualComponent.Device.Resolution);

                InteractiveWorkflow.Shell.DispatchOnUIThread(() => {
                    try {
                        var image = BitmapImageFactory.Load(filePath);
                        Clipboard.SetImage(image);
                    } catch (Exception e) when(!e.IsCriticalException())
                    {
                        InteractiveWorkflow.Shell.ShowErrorMessage(string.Format(Resources.Plots_CopyToClipboardError, e.Message));
                    } finally {
                        try {
                            File.Delete(filePath);
                        } catch (IOException) {
                        }
                    }
                });
            } catch (RPlotManagerException ex) {
                InteractiveWorkflow.Shell.ShowErrorMessage(ex.Message);
            } catch (OperationCanceledException) {
            }

            return(CommandResult.Executed);
        }
예제 #4
0
        private ImageSource GetImageFromResources(string name)
        {
            Bitmap      bmp    = null;
            ImageSource source = null;

            switch (name)
            {
            case "RProjectNode":
                bmp = Resources.RProjectNode;
                break;

            case "RFileNode":
                bmp = Resources.RFileNode;
                break;

            case "RDataNode":
                bmp = Resources.RDataNode;
                break;
            }

            if (bmp != null)
            {
                using (MemoryStream memory = new MemoryStream()) {
                    bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                    memory.Position = 0;
                    source          = BitmapImageFactory.Load(memory);
                }
            }

            return(source);
        }
예제 #5
0
        private async Task <BitmapImage> GetExpectedImageAsync(string imageType, int width, int height, int res, string name, string code)
        {
            var filePath = _testFiles.GetDestinationPath(_testMethod.Name + name + "." + imageType);
            var script   = string.Format(@"
{0}({1}, width={2}, height={3}, res={4})
{5}
dev.off()
", imageType, filePath.ToRPath().ToRStringLiteral(), width, height, res, code);

            var eval   = _workflow.ActiveWindow.InteractiveWindow.Evaluator;
            var result = await eval.ExecuteCodeAsync(script);

            return(BitmapImageFactory.Load(filePath));
        }
예제 #6
0
 public static BitmapImage ToBitmapImage(this PlotMessage plot)
 {
     return(BitmapImageFactory.Load(plot.FilePath));
 }
예제 #7
0
 public static BitmapImage ToBitmapImage(this PlotMessage plot)
 {
     return(BitmapImageFactory.Load(new MemoryStream(plot.Data)));
 }