ImageSizeHelper.cs 709 B

12345678910111213141516171819202122232425
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. namespace PicView.Data.Sizing;
  4. public static class ImageSize
  5. {
  6. public static Size GetScaledImageSize(double width, double height, Control control)
  7. {
  8. if (width <= 0 || height <= 0) { return new Size(0,0); }
  9. double maxWidth, maxHeight;
  10. var screen = Screen.ScreenHelper.GetScreen(control);
  11. var padding = 70;
  12. maxWidth = Math.Min(screen.WorkingArea.Width - padding, width);
  13. maxHeight = Math.Min(screen.WorkingArea.Height - padding, height);
  14. var aspectRatio = Math.Min(maxWidth / width, maxHeight / height);
  15. return new Size(width * aspectRatio, height * aspectRatio);
  16. }
  17. }