过去一周,我一直在努力在画布范围内转换图像
void image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var name = (Image)sender;
var translate = (CompositeTransform)name.RenderTransform;
var newPosX = Canvas.GetLeft(name) + translate.TranslateX + e.Delta.Translation.X;
var newPosY = Canvas.GetTop(name) + translate.TranslateY + e.Delta.Translation.Y;
if (!isBoundary(newPosX, DrawCanvas.ActualWidth - name.ActualWidth, 0))
translate.TranslateX += e.Delta.Translation.X;
if (!isBoundary(newPosY, DrawCanvas.ActualHeight - name.ActualHeight, 0))
translate.TranslateY += e.Delta.Translation.Y;
}
bool isBoundary(double value, double max, double min)
{
return value > max ? true : value < min ? true : false;
}
这是我的拖动代码,它运行正常,并且isBoundary函数限制了canvas内部的图像,但当我使用此代码进行缩放时
{
var translate = (CompositeTransform)name.RenderTransform;
translate.CenterX = name.ActualWidth / 2;
translate.CenterY = name.ActualHeight / 2;
translate.ScaleX += e.Delta.Translation.X*0.001 ;
translate.ScaleY += e.Delta.Translation.Y*0.001;
}
缩放也是完成但不限制画布内部和我当我缩放我的图像以使其画布大也是缩放时,当我在大小上刮胡子时它的画布(拖动)区域也在缩小。 需要帮助限制缩放及其画布问题。