WidthToBitmapScalingModeConverter.cs 1022 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Media;
  5. namespace PixiEditor.Helpers.Converters
  6. {
  7. internal class WidthToBitmapScalingModeConverter : SingleInstanceMultiValueConverter<WidthToBitmapScalingModeConverter>
  8. {
  9. public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. int? pixelWidth = values[0] as int?;
  12. double? actualWidth = values[1] as double?;
  13. if (pixelWidth == null || actualWidth == null)
  14. return DependencyProperty.UnsetValue;
  15. double zoomLevel = actualWidth.Value / pixelWidth.Value;
  16. if (zoomLevel < 1)
  17. return BitmapScalingMode.HighQuality;
  18. return BitmapScalingMode.NearestNeighbor;
  19. }
  20. public override object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  21. {
  22. throw new NotImplementedException();
  23. }
  24. }
  25. }