瀏覽代碼

Fixed resizing

Krzysztof Krysiński 6 月之前
父節點
當前提交
c1f61b7432
共有 1 個文件被更改,包括 13 次插入9 次删除
  1. 13 9
      src/PixiEditor/Models/IO/CustomDocumentFormats/SvgDocumentBuilder.cs

+ 13 - 9
src/PixiEditor/Models/IO/CustomDocumentFormats/SvgDocumentBuilder.cs

@@ -193,21 +193,25 @@ internal class SvgDocumentBuilder : IDocumentBuilder
         Surface? imgSurface = bytes is { Length: > 0 } ? Surface.Load(bytes) : null;
         Surface? finalSurface = null;
 
-        if (style.ViewboxSize.ShortestAxis > 0)
+        if (imgSurface != null)
+        {
+            if (imgSurface.Size.X != (int)image.Width.Unit?.PixelsValue ||
+                imgSurface.Size.Y != (int)image.Height.Unit?.PixelsValue)
+            {
+                var resized = imgSurface.ResizeNearestNeighbor(
+                    new VecI((int)image.Width.Unit?.PixelsValue, (int)image.Height.Unit?.PixelsValue));
+                imgSurface.Dispose();
+                imgSurface = resized;
+            }
+        }
+
+        if (style.ViewboxSize.ShortestAxis > 0 && imgSurface != null)
         {
             finalSurface = new Surface((VecI)style.ViewboxSize);
             double x = image.X.Unit?.PixelsValue ?? 0;
             double y = image.Y.Unit?.PixelsValue ?? 0;
             finalSurface.DrawingSurface.Canvas.DrawSurface(imgSurface.DrawingSurface, (int)x, (int)y);
             imgSurface.Dispose();
-
-            if (finalSurface.Size.X != (int)image.Width.Unit?.PixelsValue || finalSurface.Size.Y != (int)image.Height.Unit?.PixelsValue)
-            {
-                var resized = finalSurface.ResizeNearestNeighbor((VecI)style.ViewboxSize);
-                finalSurface.Dispose();
-                finalSurface = resized;
-            }
-
         }
 
         var graphBuilder = graph.WithImageLayerNode(