fix: OpenCvImage render clipping

This commit is contained in:
2026-02-09 12:51:18 +03:00
parent 83186538ee
commit 6179567170
+23 -16
View File
@@ -259,25 +259,32 @@ public class OpenCvImage : Control
public override void Render(DrawingContext context)
{
context.FillRectangle(new SolidColorBrush(Background), new Rect(0, 0, Bounds.Width, Bounds.Height));
if (_bitmap is null)
using (context.PushClip(new Rect(Bounds.Size)))
{
base.Render(context);
return;
context.FillRectangle(new SolidColorBrush(Background), new Rect(0, 0, Bounds.Width, Bounds.Height));
if (_bitmap is null)
{
base.Render(context);
return;
}
var (sx, sy) = ComputeStretchScale(StretchMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height);
sx *= _zoom;
sy *= _zoom;
var drawWidth = _bitmap.PixelSize.Width * sx;
var drawHeight = _bitmap.PixelSize.Height * sy;
var destRect = new Rect(
(Bounds.Width - drawWidth) / 2 + _panX,
(Bounds.Height - drawHeight) / 2 + _panY,
drawWidth, drawHeight
);
var srcRect = ComputeSourceRect(TileMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height);
context.DrawImage(_bitmap, srcRect, destRect);
}
var (sx, sy) = ComputeStretchScale(StretchMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height);
sx *= _zoom;
sy *= _zoom;
var drawWidth = _bitmap.PixelSize.Width * sx;
var drawHeight = _bitmap.PixelSize.Height * sy;
var destRect = new Rect((Bounds.Width - drawWidth) / 2 + _panX, (Bounds.Height - drawHeight) / 2 + _panY, drawWidth, drawHeight);
var srcRect = ComputeSourceRect(TileMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height);
context.DrawImage(_bitmap, srcRect, destRect);
base.Render(context);
}