0

我希望能够通过单击按钮以编程方式调整一层(选定的一层)的大小。所以基本上我有一个 ImgView32,我给它添加了图层。选择了最后一个,然后我想按下一个按钮,然后单击该按钮,我希望放大所选图层...

我希望能够画出水平和垂直的线条,以允许用户绘制房屋的布局(2D)。但我希望用户能够在没有鼠标的情况下调整线条的大小......所以他应该能够在编辑框中输入宽度和高度,然后单击按钮将尺寸应用于相应的(选定的)行。

我怎样才能在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;

但是所选图层保持相同大小并且内容缩小......我不知道我做错了什么。请帮忙。

谢谢

4

1 回答 1

1

就像是:

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);

我仍然不确定这是否是你所追求的。

于 2015-01-18T16:03:38.943 回答