缩放TRotLayer [英] Scaling the TRotLayer
问题描述
我正在处理graphics32.我正在使用示例中的给定组件TRotLayer.根据示例(Examples/Layers/RotLayer_Ex),创建的RotLayer仅与ImgView一起缩放.如果未分配ImgView.Bitmap,则RotLayer不会缩放.因此,我修改了源代码,更改了它的行为.我更改了TRotLayer.AdjustTransformation过程.这就是我所做的.
I'm working on graphics32. And I'm using the given component from its examples, the TRotLayer. Basing on the example (Examples/Layers/RotLayer_Ex), the created RotLayer only scales together with the ImgView. If ImgView.Bitmap is not assigned, the RotLayer doesn't scale. So I tinkered the source code, changing it's behavior. I changed the TRotLayer.AdjustTransformation procedure. Here's what I did.
procedure TRotLayer.AdjustTransformation;
var
ScaleX, ScaleY,
ShiftX, ShiftY: Single;
begin
Transformation.Clear;
Transformation.Translate(-BitmapCenter.X, -BitmapCenter.Y);
Transformation.Rotate(0, 0, Angle);
Transformation.Translate(Position.X, Position.Y);
Transformation.Scale(Scale.X, Scale.Y);
Transformation.Translate(Shift.X, Shift.Y);
// if Scaled and Assigned(LayerCollection) then
// with LayerCollection do
// begin
// GetViewportScale(ScaleX, ScaleY);
// GetViewportShift(ShiftX, ShiftY);
// Transformation.Scale(ScaleX, ScaleY);
// Transformation.Translate(ShiftX, ShiftY);
// end;
end;
我只是忽略了限制,只执行了.Scale过程.我传递了Scale.X和Scale.Y的值,它按预期工作.图像已调整大小,但现在我的问题是定位.如果缩放比例,图像将向上或向下移动,如果缩放比例,则图像将向右或向左移动.我只是想调整它的大小并保持它原来的位置.我注意到函数.Translate可以解决我的问题,但是我不知道该在参数中传递什么.或者我不知道如何计算要传递的值.
I just ommitted the restriction and simply executed the .Scale procedure. I passed values for Scale.X and Scale.Y and it worked as I expected. The image was resized but now my problem is the positioning. The image moves up or down if I scale it's height then it moves right or left if I scale it's width. I just wanted it to resize and just stay in it's original position. I noticed that the function .Translate can possibly fix my problem but I don't know what to pass in the parameters. Or I don't know how to compute the values to pass.
任何人都可以帮助我解决这个问题.谢谢.
Anyone can help me with this problem. Thanks.
推荐答案
伪代码:
-
计算原始范围:
Calculate the original bounds:
Transformation.SrcRect := FloatRect(0, 0, Old.Width, Old.Height);
将原点移动到该边界的中心:
Shift the origin to the center of that bounds:
Transformation.Translate(-0.5 * Old.Width, -0.5 * Old.Height);
围绕新起点旋转:
Transformation.Rotate(0, 0, Degrees);
规模
计算新界限:
New.Bounds := Transformation.GetTransformedBounds;
将原点移回新界限的(0,0):
Shift the origin back to (0, 0) of the new bounds:
Transformation.Translate(0.5 * New.Width, 0.5 * New.Height);
对于Graphics32示例(无缩放比例),您还可以查看按实际角度旋转位图.
You might also take a look at Rotate bitmap by real angle for a Graphics32 example (without scaling).
这篇关于缩放TRotLayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!