Good afternoon.
I’m working on a drawing program that allows the user to drag and drop TImages loaded with a Bitmap over a canvas. (In a Firemonkey HD application in RAD Studio XE2) The user can then change x and y scales and rotation before saving the image.
All TImages are kept in a list and this list is then written to the underlying canvas using this simple procedure:
for i := 0 to DroppedList.Count - 1 do
begin
AImage := DroppedList[i];
SourceRect.Left := 0;
SourceRect.Right := AImage.Bitmap.Width;
SourceRect.Top := 0;
Sourcerect.Bottom := AImage.Bitmap.Height;
TargetRect.Left := AImage.Position.X;
TargetRect.Right := AImage.Position.X + AImage.Bitmap.Width;
TargetRect.Top := AImage.Position.Y;
TargetRect.Bottom := AImage.Position.Y + AImage.Bitmap.Height;
with FImage.Bitmap do
begin
Canvas.BeginScene;
Canvas.DrawBitmap(AImage.Bitmap, SourceRect, TargetRect, 1, True);
Canvas.EndScene;
BitmapChanged
end;
end;
FImage.Bitmap.SaveToFile('test.bmp');
The problem with this is that transformations to the scale and rotation of the images that are visible in the window are not taken into account by DrawBitmap, and are lost when saving.
I am looking for a way to apply the transformations to the bitmap before drawing it to the background.
I was unable to find any info on this, so i was hoping someone here could help.
Thank you,
Daniël
the problem seems to be that the Scaling and the Rotation are applyed to a source TImage. In this “source TImage”, the transformations are not done to the bitmap but rather at the TImage level (beause it’s a TControl and as all TControl they can be scaled and rotated). Later you copy the source Bitmap elsewhere, but actually this Bitmap has never changed.
So would have to rotate and scale the bitmap in the loop, according to the settings in the source TImage:
This simple code sample explains well the problem. For example, RotatationAngle is a property of AImage and not of AImage.Bitmap.
A workaround that would avoid to implement the transformations would be to use TControl.MakeScreenshot(). (to be verified, this coulds fail)