啊哈!我找到了!在分析了我发布的链接后,我意识到“嘿,他没有在任何地方设置缩放比例。然后我发现了问题。我在创造一个新的
Matrix
每一次。这不是正确的方法。它应该缩放/平移
转型:
private void ZoomToPoint(float scale, Point origin)
{
var matrix = this.TransformMatrix;
matrix.Translate(-origin.X, -origin.Y, MatrixOrder.Append);
matrix.Scale(scale, scale, MatrixOrder.Append);
matrix.Translate(origin.X, origin.Y, MatrixOrder.Append);
this.TransformMatrix = matrix;
}
对此的呼吁是:
// Zoom in
this.ZoomToPoint(6 / 5.0f, e.Location);
// Zoom out
this.ZoomToPoint(5 / 6.0f, e.Location);