forked from amkovkov/GranuSightSoftware2
fix: OpenCvImage render clipping
This commit is contained in:
+23
-16
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user