Create an empty form with this code in FormCreate:
var
aImage: TImage;
procedure TfrmMain.FormCreate(Sender: TObject);
var
aBitmap: TBitmap;
begin
aImage := TImage.Create(frmMain);
aImage.Parent := frmMain;
aImage.Width := 500;
aImage.Height := 500;
aBitmap := TBitmap.Create;
aBitmap.Width := 500;
aBitmap.Height := 500;
aBitmap.Canvas.Brush.Color := clRed;
aBitmap.Canvas.FillRect(0,0,500,500);
aBitmap.Canvas.Brush.Color := clBlue;
aBitmap.Canvas.FillRect(150,150,350,350);
aImage.Canvas.Draw(0,0,aBitmap);
aBitmap.SaveToFile('/tmp/test.bmp');
end;
Expected result:
TImage on form = red background with blue box
Saved bitmap file = red background with blue box
Actual result:
TImage on form = blue background with red box ** !!! **
Saved bitmap file = red background with blue box
See attachments.
Why is the image on the form incorrect?