我正在尝试在 Lua(Codea)中构建“缩放以适应”算法。想象一下 Canvas 上任意位置的形状。我想自动放大这个形状的中心,使其占据画布的大部分并以它为中心。最后,我希望能够缩小到初始情况,所以矩阵应该可以完成这项工作。有没有一种简单的方法可以做到这一点?欢迎任何代码,即使不是 Lua 代码。
问问题
341 次
1 回答
1
在 C# 中,
double aspectRatio = shape.Width / shape.Height;
if (aspectRatio > 1)
{
// Width defines the layout
double origShapeWidth = shape.Width;
shape.Width = panel.Width;
shape.Height = panel.Width * shape.Height / origShapeWidth;
// Center the shape
double margin = (panel.Height - shape.Height) / 2;
shape.Margin = new Thickness(0, margin, 0, margin);
}
else
{
// Height defines the layout
double origShapeHeight = shape.Height;
shape.Height = panel.Height;
shape.Width = panel.Height * shape.Width / origShapeHeight;
// Center the shape
double margin = (panel.Width - shape.Width) / 2;
shape.Margin = new Thickness(margin, 0, margin, 0);
}
于 2013-08-04T23:30:06.843 回答