Browse Source

Fixed bitmap blending

There ares till some render bugs.
Krzysztof Krysiński 5 years ago
parent
commit
c8418f063e
1 changed files with 7 additions and 11 deletions
  1. 7 11
      PixiEditorDotNetCore3/ViewModels/ViewModelMain.cs

+ 7 - 11
PixiEditorDotNetCore3/ViewModels/ViewModelMain.cs

@@ -155,6 +155,7 @@ namespace PixiEditor.ViewModels
         }
         }
 
 
         private ToolsManager primaryToolSet;
         private ToolsManager primaryToolSet;
+        private WriteableBitmap _lastBlendedBitmap;
 
 
         public ViewModelMain()
         public ViewModelMain()
         {
         {
@@ -178,15 +179,6 @@ namespace PixiEditor.ViewModels
             primaryToolSet.SetTool(SelectedTool);
             primaryToolSet.SetTool(SelectedTool);
         }
         }
 
 
-        public Image BuildFinalImage()
-        {
-            if (ActiveLayer == null) return null;
-            WriteableBitmap bitmap = BlendLayersBitmaps();
-            Image finalImage =  ImageGenerator.GenerateForPixelArts(ActiveLayer.Width,ActiveLayer.Height);
-            finalImage.Source = bitmap;
-            return finalImage;
-        }
-
         public WriteableBitmap BlendLayersBitmaps()
         public WriteableBitmap BlendLayersBitmaps()
         {
         {
             Rect size = new Rect(new Size(ActiveLayer.Width, ActiveLayer.Height));
             Rect size = new Rect(new Size(ActiveLayer.Width, ActiveLayer.Height));
@@ -315,7 +307,8 @@ namespace PixiEditor.ViewModels
         {
         {
             if (ActiveLayer != null)
             if (ActiveLayer != null)
             {
             {
-                ActiveImage = BuildFinalImage();
+                _lastBlendedBitmap = BlendLayersBitmaps();
+                ActiveImage.Source = _lastBlendedBitmap;
             }
             }
         }
         }
 
 
@@ -323,7 +316,10 @@ namespace PixiEditor.ViewModels
         {
         {
             if (ActiveLayer != null)
             if (ActiveLayer != null)
             {
             {
-                ActiveImage.Source = ActiveLayer.LayerBitmap;
+                Rect size = new Rect(new Size(ActiveLayer.Height, ActiveLayer.Width));
+                 _lastBlendedBitmap.Blit(size, ActiveLayer.LayerBitmap,
+                    size);
+                ActiveImage.Source = _lastBlendedBitmap;
             }
             }
         }
         }