Browse Source

Fix BitmapScaling setting only affecting the next render

pull/165/head
Ionite 1 year ago
parent
commit
378473b8d9
No known key found for this signature in database
  1. 41
      StabilityMatrix.Avalonia/Controls/AdvancedImageBox.axaml.cs

41
StabilityMatrix.Avalonia/Controls/AdvancedImageBox.axaml.cs

@ -1213,6 +1213,24 @@ public class AdvancedImageBox : TemplatedControl
}
public bool HaveSelection => !IsRectEmpty(SelectionRegion);
private BitmapInterpolationMode? _bitmapInterpolationMode;
/// <summary>
/// Gets or sets the current Bitmap Interpolation Mode
/// </summary>
public BitmapInterpolationMode BitmapInterpolationMode
{
get => _bitmapInterpolationMode ??= RenderOptions.GetBitmapInterpolationMode(this);
set
{
if (_bitmapInterpolationMode == value)
return;
_bitmapInterpolationMode = value;
RenderOptions.SetBitmapInterpolationMode(this, value);
}
}
#endregion
#region Constructor
@ -1262,29 +1280,26 @@ public class AdvancedImageBox : TemplatedControl
return;
if (renderOnlyCursorTracker && _trackerImage is null)
return;
var isHighZoom = ZoomFactor > PixelGridZoomThreshold;
// If we're in high zoom, switch off bitmap interpolation mode
// Otherwise use high quality
BitmapInterpolationMode = isHighZoom
? BitmapInterpolationMode.None
: BitmapInterpolationMode.HighQuality;
InvalidateVisual();
}
public override void Render(DrawingContext context)
{
//Debug.WriteLine($"Render: {DateTime.Now.Ticks}");
base.Render(context);
var zoomFactor = ZoomFactor;
var shouldDrawPixelGrid =
IsPixelGridEnabled
&& SizeMode == SizeModes.Normal
&& zoomFactor > PixelGridZoomThreshold;
var isHighZoom = zoomFactor > PixelGridZoomThreshold;
// If we're in high zoom, switch off bitmap interpolation mode
// Otherwise use high quality
RenderOptions.SetBitmapInterpolationMode(
this,
isHighZoom ? BitmapInterpolationMode.None : BitmapInterpolationMode.HighQuality
);
&& ZoomFactor > PixelGridZoomThreshold;
var viewPortSize = ViewPortSize;
// Draw Grid

Loading…
Cancel
Save