Delphi ImgView32 中的 Graphics32 调整图层大小
Delphi Graphics32 resize layer in ImgView32
我希望能够通过单击按钮以编程方式调整一层(选定的一层)的大小。
所以基本上我有一个 ImgView32,我向它添加了层。最后一个被选中,然后我想按下一个按钮和那个按钮的onClick我想要放大所选图层...
我希望能够绘制水平线和垂直线,以允许用户绘制房屋布局(二维)。但我希望用户能够在没有鼠标的情况下调整线条的大小......所以他应该能够在编辑框中输入宽度和高度,然后单击按钮将尺寸应用于相应的(选定的)线。
我如何在 graphics32 中做到这一点?
我这样试过:
var
orig,Tmp: TBitmap32;
Transformation: TAffineTransformation;
begin
Tmp := TBitmap32.Create;
Orig := TBitmap32.Create;
Transformation := TAffineTransformation.Create;
if Selection is TBitmapLayer then
begin
orig := TBitmapLayer(Selection).Bitmap;
try
Transformation.BeginUpdate;
Transformation.SrcRect := FloatRect(0, 0, orig.Width+200, orig.Height+200);
Transformation.Translate(-0.5 * orig.Width, -0.5 * orig.Height);
tmp.SetSize(200,200);
Transformation.Translate(0.5 * Tmp.Width, 0.5 * Tmp.Height);
Transformation.EndUpdate;
orig.DrawMode := dmTransparent;
Transform(Tmp, orig, Transformation);
orig.Assign(Tmp);
orig.DrawMode := dmTransparent;
finally
Transformation.Free;
Tmp.Free;
end;
end;
end;
但选中的图层大小不变,内容缩小了...
我不知道我做错了什么。
请帮忙
谢谢
类似于:
begin
if Selection is TBitmapLayer then
begin
TBitmapLayer(Selection).Location := FloatRect(TBitmapLayer(Selection).Location.Left,
TBitmapLayer(Selection).Location.Top, TBitmapLayer(Selection).Location.Right + 200, TBitmapLayer(Selection).Location.Bottom + 200);
end;
end;
将使层宽 200 像素(在 x 和 y 维度上)。这样做,如果没有另外指定,内容将(通常)被拉伸。
丑陋的赋值可以使用像 IncreaseRect() 这样的函数来更优雅地编写,但是它不存在,但必须由您自己编写。
它可能看起来像:
function IncreaseRect(SourceRect: TFloatRect; IncX, IncY: TFloat): TFloatRect;
begin
Result := FloatRect(SourceRect.Left, SourceRect.Top,
SourceRect.Right + IncX, SourceRect.Top + IncY);
end;
并用
调用
TBitmapLayer(Selection).Location := IncreaseRect(TBitmapLayer(Selection).Location, 200, 200);
我仍然不确定这是否是您想要的。
我希望能够通过单击按钮以编程方式调整一层(选定的一层)的大小。 所以基本上我有一个 ImgView32,我向它添加了层。最后一个被选中,然后我想按下一个按钮和那个按钮的onClick我想要放大所选图层...
我希望能够绘制水平线和垂直线,以允许用户绘制房屋布局(二维)。但我希望用户能够在没有鼠标的情况下调整线条的大小......所以他应该能够在编辑框中输入宽度和高度,然后单击按钮将尺寸应用于相应的(选定的)线。
我如何在 graphics32 中做到这一点?
我这样试过:
var
orig,Tmp: TBitmap32;
Transformation: TAffineTransformation;
begin
Tmp := TBitmap32.Create;
Orig := TBitmap32.Create;
Transformation := TAffineTransformation.Create;
if Selection is TBitmapLayer then
begin
orig := TBitmapLayer(Selection).Bitmap;
try
Transformation.BeginUpdate;
Transformation.SrcRect := FloatRect(0, 0, orig.Width+200, orig.Height+200);
Transformation.Translate(-0.5 * orig.Width, -0.5 * orig.Height);
tmp.SetSize(200,200);
Transformation.Translate(0.5 * Tmp.Width, 0.5 * Tmp.Height);
Transformation.EndUpdate;
orig.DrawMode := dmTransparent;
Transform(Tmp, orig, Transformation);
orig.Assign(Tmp);
orig.DrawMode := dmTransparent;
finally
Transformation.Free;
Tmp.Free;
end;
end;
end;
但选中的图层大小不变,内容缩小了... 我不知道我做错了什么。 请帮忙
谢谢
类似于:
begin
if Selection is TBitmapLayer then
begin
TBitmapLayer(Selection).Location := FloatRect(TBitmapLayer(Selection).Location.Left,
TBitmapLayer(Selection).Location.Top, TBitmapLayer(Selection).Location.Right + 200, TBitmapLayer(Selection).Location.Bottom + 200);
end;
end;
将使层宽 200 像素(在 x 和 y 维度上)。这样做,如果没有另外指定,内容将(通常)被拉伸。
丑陋的赋值可以使用像 IncreaseRect() 这样的函数来更优雅地编写,但是它不存在,但必须由您自己编写。
它可能看起来像:
function IncreaseRect(SourceRect: TFloatRect; IncX, IncY: TFloat): TFloatRect;
begin
Result := FloatRect(SourceRect.Left, SourceRect.Top,
SourceRect.Right + IncX, SourceRect.Top + IncY);
end;
并用
调用TBitmapLayer(Selection).Location := IncreaseRect(TBitmapLayer(Selection).Location, 200, 200);
我仍然不确定这是否是您想要的。