Browse Source

Fixed divide by zero bug

flabbet 4 năm trước cách đây
mục cha
commit
4fb85f525c

+ 3 - 3
PixiEditor/Models/DataHolders/Document.cs

@@ -59,11 +59,11 @@ namespace PixiEditor.Models.DataHolders
             }
         }
 
-        private WriteableBitmap _previewImage;
+        private WriteableBitmap previewImage;
 
         public WriteableBitmap PreviewImage
         {
-            get => _previewImage;
+            get => previewImage;
         }
 
         private string documentFilePath = string.Empty;
@@ -226,7 +226,7 @@ namespace PixiEditor.Models.DataHolders
 
         public void UpdatePreviewImage()
         {
-            _previewImage = BitmapUtils.GeneratePreviewBitmap(this, 30, 20);
+            previewImage = BitmapUtils.GeneratePreviewBitmap(this, 30, 20);
             RaisePropertyChanged(nameof(PreviewImage));
         }
 

+ 2 - 2
PixiEditor/Models/ImageManipulation/BitmapUtils.cs

@@ -100,8 +100,8 @@ namespace PixiEditor.Models.ImageManipulation
                     new Rect(0, 0, layer.Width, layer.Height));
             }
 
-            int width = document.Width >= document.Height ? maxPreviewWidth : document.Width / (document.Height / maxPreviewHeight);
-            int height = document.Height > document.Width ? maxPreviewHeight : document.Height / (document.Width / maxPreviewWidth);
+            int width = document.Width >= document.Height ? maxPreviewWidth : (int)Math.Ceiling(document.Width / ((float)document.Height / maxPreviewHeight));
+            int height = document.Height > document.Width ? maxPreviewHeight : (int)Math.Ceiling(document.Height / ((float)document.Width / maxPreviewWidth));
 
             return previewBitmap.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
         }

+ 1 - 1
PixiEditor/ViewModels/SubViewModels/Main/IoViewModel.cs

@@ -38,7 +38,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
             Owner.BitmapManager.MouseController.MouseUp(new MouseEventArgs(
                 Mouse.PrimaryDevice,
-                (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));         
+                (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
         }
 
         public void KeyDown(object parameter)