[英]AdornerLayer goes outside Border if I zoom the picture WPF
I created the logic that crops an image that is contained inside a border that is inside a grid. 我创建了一个逻辑,用于裁剪包含在网格内部边框内的图像。 The grid has many borders, so this grid will have many pictures.
网格有很多边框,所以这个网格会有很多图片。 The problem is that when I zoom the picture the logic zoomed the picture (which is okay) but when I use the crop logic the
AdornerLayer
goes outside the border like the picture: 问题是,当我缩放图片时,逻辑会缩放图片(这没关系),但是当我使用裁剪逻辑时,
AdornerLayer
像图片一样AdornerLayer
边界:
On this image the pic doesn't have zoom, so the AdornerLayer
is correct: 在此图像上,pic没有缩放,因此
AdornerLayer
是正确的:
The code that I'm using to add the crop to the image: 我用来将裁剪添加到图像的代码:
private void AddCropToElement(FrameworkElement fel, System.Drawing.Image img)
{
if (!cropElements.ContainsKey(Convert.ToString(((Image)fel).Source)))
{
if (_felCur != null)
{
RemoveCropFromCur();
}
rcInterior = new Rect(
fel.ActualWidth * 0.2,
fel.ActualHeight * 0.2,
fel.ActualWidth * 0.6,
fel.ActualHeight * 0.6);
rectMoving = false;
Rect newRect = scaleRect(rcInterior, img);
imgCropMove = img;
AdornerLayer aly = AdornerLayer.GetAdornerLayer(fel);
_clp = new CroppingAdorner(fel, rcInterior);
aly.Add(_clp);
cropElements.Add(Convert.ToString(((Image)fel).Source), fel);
imageCropped = _clp.Crop(new System.Drawing.Bitmap(img), newRect);
_clp.CropChanged += HandleCropChanged;
_felCur = fel;
}
}
In this case the object named fel is the picture that I want to crop and the Border is his parent. 在这种情况下,名为fel的对象是我要裁剪的图片,而Border是他的父级。
How I can fix the problem of the AdornerLayout that goes outside if the image is zoomed? 如果图像被缩放,我如何解决AdornerLayout外出的问题?
Are you using the default Window Adorner or have you created a custom AdornerDecorator around your Border in your XAML? 您使用的是默认的Window Adorner,还是在XAML中围绕边框创建了自定义AdornerDecorator?
<AdornerDecorator>
<Border>...</Border>
</AdornerDecorator>
Additionally, if you are applying a zoom factor on your Border, you can add a Binding on your cropping display rectangle to match the Scale on your Border object. 此外,如果要在边框上应用缩放系数,则可以在裁剪显示矩形上添加“绑定”以匹配“边框”对象上的“缩放”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.