I want to be able to programatically resize one layer (the selected one) on click of a button. So basically I have an ImgView32, and I add layers to it. The last one is selected, then I want to press a button and onClick of that button I want the selected layer to be enlarged...
I want to be able to draw lines horizontal and vertical, in order to allow the user to draw the layout of a house (in 2D). But I want the user to be able to resize a line without the mouse... so he should be able to enter the width and height in editboxes and on click of a button apply the dimensions to the respective (selected) line.
How can I do that in graphics32?
I tried like this:
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;
But the selected layer remains the same size and the contents shrink... I do not know what I am doing wrong. Please help.
Thank you
Something like:
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;
would make the layer wider by 200 pixel (in both x- and y- dimension). Doing so, the content will (typically) be stretched, if not specified otherwise.
The ugly assignment can be written more elegantly using a function like IncreaseRect(), which however is not present, but must be written by yourself.
It could look like:
function IncreaseRect(SourceRect: TFloatRect; IncX, IncY: TFloat): TFloatRect;
begin
Result := FloatRect(SourceRect.Left, SourceRect.Top,
SourceRect.Right + IncX, SourceRect.Top + IncY);
end;
and called with
TBitmapLayer(Selection).Location := IncreaseRect(TBitmapLayer(Selection).Location, 200, 200);
Still I'm not sure if this is what you're after.