public static bool ExportLayersAsPNG(List <string> Layers) { try { if (Methods.Solution.CurrentSolution.CurrentScene?.AllLayers == null || !Methods.Solution.CurrentSolution.CurrentScene.AllLayers.Any()) { return(false); } var dialog = new GenerationsLib.Core.FolderSelectDialog() { Title = "Select folder to save each exported layer image to" }; if (!dialog.ShowDialog()) { return(false); } int fileCount = 0; List <EditorLayer> LayerList = new List <EditorLayer>(); foreach (var entry in Layers) { if (Methods.Solution.CurrentSolution.CurrentScene.AllLayers.ToList().Exists(x => x.Name == entry)) { LayerList.AddRange(Methods.Solution.CurrentSolution.CurrentScene.AllLayers.Where(x => x.Name == entry)); } } foreach (var editorLayer in LayerList) { string fileName = System.IO.Path.Combine(dialog.FileName, editorLayer.Name + ".png"); if (!Methods.Internal.Common.CanWriteFile(fileName)) { Methods.Internal.Common.ShowError($"Layer export aborted. {fileCount} images saved."); return(false); } using (var bitmap = new System.Drawing.Bitmap(editorLayer.Width * Methods.Solution.SolutionConstants.TILE_SIZE, editorLayer.Height * Methods.Solution.SolutionConstants.TILE_SIZE)) using (var g = System.Drawing.Graphics.FromImage(bitmap)) { editorLayer.Draw(g); bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); ++fileCount; } } MessageBox.Show($"Layer export succeeded. {fileCount} images saved.", "Success!", MessageBoxButton.OK, MessageBoxImage.Information); return(true); } catch (Exception ex) { Methods.Internal.Common.ShowError("An error occurred: " + ex.Message); return(false); } }
public void SelectNewWorkspaceFolder() { GenerationsLib.Core.FolderSelectDialog fsd = new GenerationsLib.Core.FolderSelectDialog(); if (fsd.ShowDialog()) { AddWorkspaceDialog awd = new AddWorkspaceDialog(); awd.Owner = Instance; if (awd.ShowDialog() == true) { Workspace workspace = new Workspace(awd.WorkspaceName, fsd.FileName, awd.SelectedFormat); AddWorkspaceFolder(workspace); } } }