Kaynağa Gözat

Export image fixed

flabbet 2 yıl önce
ebeveyn
işleme
ed81137cca

+ 1 - 0
src/ChunkyImageLib/ChunkyImageLib.csproj

@@ -16,6 +16,7 @@
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="WriteableBitmapEx" Version="1.6.8" />
   </ItemGroup>
 
   <ItemGroup>

+ 7 - 0
src/PixiEditor/Helpers/ProcessHelper.cs

@@ -1,5 +1,6 @@
 using System.ComponentModel;
 using System.Diagnostics;
+using System.IO;
 using System.Security.Principal;
 
 namespace PixiEditor.Helpers;
@@ -28,4 +29,10 @@ internal static class ProcessHelper
     {
         return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
     }
+
+    public static void OpenInExplorer(string path)
+    {
+        string fixedPath = Path.GetFullPath(path);
+        Process.Start("explorer.exe", $"/select,\"{fixedPath}\"");
+    }
 }

+ 4 - 3
src/PixiEditor/Models/Dialogs/ExportFileDialog.cs

@@ -1,4 +1,5 @@
 using System.Windows;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Models.Enums;
 using PixiEditor.Views;
 using PixiEditor.Views.Dialogs;
@@ -15,10 +16,10 @@ internal class ExportFileDialog : CustomDialog
 
     private int fileWidth;
 
-    public ExportFileDialog(Size fileDimensions)
+    public ExportFileDialog(VecI size)
     {
-        FileHeight = (int)fileDimensions.Height;
-        FileWidth = (int)fileDimensions.Width;
+        FileHeight = size.X;
+        FileWidth = size.Y;
     }
 
     public int FileWidth

+ 10 - 6
src/PixiEditor/Models/IO/Exporter.cs

@@ -111,7 +111,7 @@ internal class Exporter
     /// </summary>
     /// <param name="bitmap">Bitmap to be saved as file.</param>
     /// <param name="fileDimensions">Size of file.</param>
-    public static void Export(WriteableBitmap bitmap, Size fileDimensions)
+    public static bool Export(WriteableBitmap bitmap, VecI fileDimensions, out string path)
     {
         ExportFileDialog info = new ExportFileDialog(fileDimensions);
 
@@ -120,7 +120,13 @@ internal class Exporter
         {
             if (encodersFactory.ContainsKey(info.ChosenFormat))
                 SaveAs(encodersFactory[info.ChosenFormat](), info.FilePath, info.FileWidth, info.FileHeight, bitmap);
+            
+            path = info.FilePath;
+            return true;
         }
+
+        path = string.Empty;
+        return false;
     }
     public static void SaveAsGZippedBytes(string path, Surface surface)
     {
@@ -162,11 +168,9 @@ internal class Exporter
         try
         {
             bitmap = bitmap.Resize(exportWidth, exportHeight, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
-            using (var stream = new FileStream(savePath, FileMode.Create))
-            {
-                encoder.Frames.Add(BitmapFrame.Create(bitmap));
-                encoder.Save(stream);
-            }
+            using var stream = new FileStream(savePath, FileMode.Create);
+            encoder.Frames.Add(BitmapFrame.Create(bitmap));
+            encoder.Save(stream);
         }
         catch (Exception err)
         {

+ 0 - 3
src/PixiEditor/PixiEditor.csproj

@@ -220,9 +220,6 @@
 		<PackageReference Include="PixiEditor.Parser.Skia" Version="3.0.0" />
 		<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
 		<PackageReference Include="WpfAnimatedGif" Version="2.0.2" />
-		<PackageReference Include="WriteableBitmapEx">
-			<Version>1.6.8</Version>
-		</PackageReference>
 		<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.435">
 		  <PrivateAssets>all</PrivateAssets>
 		  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 9 - 4
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -273,11 +273,16 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     [Command.Basic("PixiEditor.File.Export", "Export", "Export image", CanExecute = "PixiEditor.HasDocument", Key = Key.S, Modifiers = ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Shift)]
     public void ExportFile()
     {
-        /*
         ViewModelMain.Current.ActionDisplay = "";
-        WriteableBitmap bitmap = Owner.BitmapManager.ActiveDocument.Renderer.FinalBitmap;
-        Exporter.Export(bitmap, new Size(bitmap.PixelWidth, bitmap.PixelHeight));
-        */
+        DocumentViewModel doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
+        if (doc is null)
+            return;
+
+        var bitmap = doc.Bitmaps[ChunkResolution.Full];
+        if (Exporter.Export(bitmap, new VecI(bitmap.PixelWidth, bitmap.PixelHeight), out string path))
+        {
+            ProcessHelper.OpenInExplorer(path);
+        }
     }
 
     private void UpdateMaxRecentlyOpened(object parameter)

+ 2 - 3
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -112,9 +112,8 @@ internal partial class HelloTherePopup : Window
 
     private void OpenInExplorer(object parameter)
     {
-        string path = Path.GetFullPath((string)parameter);
-
-        Process.Start("explorer.exe", $"/select,\"{path}\"");
+        if (parameter is not string value) return;
+        ProcessHelper.OpenInExplorer(value);
     }
 
     private bool CanOpenInExplorer(object parameter) => File.Exists((string)parameter);