0

ボタンをクリックするだけで、1 つのレイヤー (選択したレイヤー) のサイズをプログラムで変更できるようにしたいと考えています。つまり、基本的に ImgView32 があり、それにレイヤーを追加します。最後のレイヤーを選択して、ボタンを押してそのボタンのonClickにしたい選択したレイヤーを拡大したい...

ユーザーが家のレイアウトを(2Dで)描画できるようにするために、水平および垂直の線を描画できるようにしたいと考えています。しかし、ユーザーがマウスなしで行のサイズを変更できるようにしたいので、編集ボックスに幅と高さを入力し、ボタンをクリックすると、それぞれの (選択された) 行に寸法を適用できるようにする必要があります。

グラフィックス32でそれを行うにはどうすればよいですか?

私はこのように試しました:

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 に答える