Browse Source

Fixed HelloTherePopup preview

CPKreuz 3 years ago
parent
commit
c4c8c5591c

+ 4 - 2
PixiEditor/Models/DataHolders/RecentlyOpenedDocument.cs

@@ -86,8 +86,10 @@ namespace PixiEditor.Models.DataHolders
                     return null;
                     return null;
                 }
                 }
 
 
-                // TODO: Make this work
-                Surface surface = Surface.Combine(serializableDocument.Width, serializableDocument.Height, serializableDocument.Layers.Select(x => (x.ToSKImage(), new Coordinates(x.OffsetX, x.OffsetY))));
+                using Surface surface = Surface.Combine(serializableDocument.Width, serializableDocument.Height,
+                          serializableDocument.Layers
+                              .Where(x => x.Opacity > 0.8)
+                              .Select(x => (x.ToSKImage(), new Coordinates(x.OffsetX, x.OffsetY))));
 
 
                 return surface.ToWriteableBitmap();
                 return surface.ToWriteableBitmap();
             }
             }

+ 7 - 7
PixiEditor/Models/DataHolders/Surface.cs

@@ -121,17 +121,17 @@ namespace PixiEditor.Models.DataHolders
             SkiaSurface.Canvas.DrawPoint(x, y, drawingPaint);
             SkiaSurface.Canvas.DrawPoint(x, y, drawingPaint);
         }
         }
 
 
-        public unsafe byte[] ToPbgra32ByteArray()
+        public unsafe byte[] ToByteArray(SKColorType colorType = SKColorType.Bgra8888, SKAlphaType alphaType = SKAlphaType.Premul)
         {
         {
-            var imageInfo = new SKImageInfo(Width, Height, SKColorType.Bgra8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb());
+            var imageInfo = new SKImageInfo(Width, Height, colorType, alphaType, SKColorSpace.CreateSrgb());
 
 
             byte[] buffer = new byte[Width * Height * 4];
             byte[] buffer = new byte[Width * Height * 4];
             fixed (void* pointer = buffer)
             fixed (void* pointer = buffer)
             {
             {
-                using SKPixmap map = new(imageInfo, new IntPtr(pointer));
-                using SKSurface surface = SKSurface.Create(map);
-                var newSurface = CreateSurface(Width, Height);
-                surface.Draw(newSurface.Canvas, 0, 0, ReplacingPaint);
+                if (!SkiaSurface.Snapshot().ReadPixels(imageInfo, new IntPtr(pointer)))
+                {
+                    throw new InvalidOperationException("Could not read image into buffer");
+                }
             }
             }
 
 
             return buffer;
             return buffer;
@@ -142,7 +142,7 @@ namespace PixiEditor.Models.DataHolders
             WriteableBitmap result = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32, null);
             WriteableBitmap result = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32, null);
             result.Lock();
             result.Lock();
             var dirty = new Int32Rect(0, 0, Width, Height);
             var dirty = new Int32Rect(0, 0, Width, Height);
-            result.WritePixels(dirty, ToPbgra32ByteArray(), Width * 4, 0);
+            result.WritePixels(dirty, ToByteArray(), Width * 4, 0);
             result.AddDirtyRect(dirty);
             result.AddDirtyRect(dirty);
             result.Unlock();
             result.Unlock();
             return result;
             return result;

+ 1 - 1
PixiEditor/Models/Layers/Layer.cs

@@ -516,7 +516,7 @@ namespace PixiEditor.Models.Layers
         /// </summary>
         /// </summary>
         public byte[] ConvertBitmapToBytes()
         public byte[] ConvertBitmapToBytes()
         {
         {
-            return LayerBitmap.ToPbgra32ByteArray();
+            return LayerBitmap.ToByteArray();
         }
         }
 
 
         private Dictionary<Coordinates, SKColor> GetRelativePosition(Dictionary<Coordinates, SKColor> changedPixels)
         private Dictionary<Coordinates, SKColor> GetRelativePosition(Dictionary<Coordinates, SKColor> changedPixels)

+ 1 - 1
PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -119,7 +119,7 @@
                                                 Style="{StaticResource DarkRoundButton}"
                                                 Style="{StaticResource DarkRoundButton}"
                                                 x:Name="fileButton">
                                                 x:Name="fileButton">
                                             <Grid Width="100" Height="100">
                                             <Grid Width="100" Height="100">
-                                                <Image Source="{Binding PreviewBitmap}" Margin="20"/>
+                                                <Image Source="{Binding PreviewBitmap}" RenderOptions.BitmapScalingMode="NearestNeighbor" Margin="20"/>
                                                 <Border Grid.Row="1" Height="8" Width="8" x:Name="extensionBorder" Margin="5"
                                                 <Border Grid.Row="1" Height="8" Width="8" x:Name="extensionBorder" Margin="5"
                                                         Background="{Binding FileExtension, Converter={converters:FileExtensionToColorConverter}}" 
                                                         Background="{Binding FileExtension, Converter={converters:FileExtensionToColorConverter}}" 
                                                         VerticalAlignment="Bottom" HorizontalAlignment="Right">
                                                         VerticalAlignment="Bottom" HorizontalAlignment="Right">

+ 1 - 1
PixiEditorTests/ModelsTests/DataHoldersTests/SurfaceTests.cs

@@ -47,7 +47,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
             using Surface surface = new Surface(2, 4, bytes);
             using Surface surface = new Surface(2, 4, bytes);
             Assert.Equal(new SKColor(141, 121, 123, 255), surface.GetSRGBPixel(0, 0));
             Assert.Equal(new SKColor(141, 121, 123, 255), surface.GetSRGBPixel(0, 0));
             Assert.Equal(new SKColor(110, 44, 84, 128), surface.GetSRGBPixel(0, 1));
             Assert.Equal(new SKColor(110, 44, 84, 128), surface.GetSRGBPixel(0, 1));
-            var newBytes = surface.ToPbgra32ByteArray();
+            var newBytes = surface.ToByteArray();
             Assert.Equal(bytes, newBytes);
             Assert.Equal(bytes, newBytes);
         }
         }