I suppose it is related to the alpha channel added from the BGRA bitmap.
It makes sense to assign the bitmap so that if the window is redrawn, the image will be kept.
Though to be sure the image you assign is not transparent, you can use the function MakeBitmapCopy:
procedure TForm1.Button1Click(Sender: TObject);
var bmpCopy: TBitmap;
begin
bgraImg := TBGRABitmap.Create;
if OpenPictureDialog1.Execute then
begin
bgraImg.LoadFromFile(OpenPictureDialog1.FileName);
bmpCopy := bgraImg.MakeBitmapCopy(clForm);
Image1.Picture.Assign(bmpCopy);
bmpCopy.Free;
end;
end;
Note that bgraImg variable would normally either be:
- a local variable in the Button1Click function
- an object variable in TForm1
And would need to be freed, either at the end of Button1Click function or in FormDestroy.
If you want also the rectangle drawn on the image to be persistent, you can draw it within the image:
procedure TForm1.Button2Click(Sender: TObject);
begin
Image1.Picture.Bitmap.Canvas.Brush.Color := clWhite;
Image1.Picture.Bitmap.Canvas.Rectangle(10, 10, 200, 200);
end;
Explanation: it is to draw on the canvas of the picture contained in the image. The picture in fact can contain any kind of graphic things, not just a bitmap, so here we specify we access it as a bitmap.