How to use Image1.Bitmap.BitmapChanged;

384 Views Asked by At

Bitmap.BitmapChanged; is protected in FMX.Graphics so I cannot use the procedure.

Useing a TImage or TImageControler I am drawing a line but the line does not show.

I am using this snippet:

imgc1.Bitmap.Canvas.BeginScene;
imgc1.Bitmap.Canvas.DrawLine(FStartPoint,FEndPoint, 100);
imgc1.Bitmap.Canvas.EndScene;
imgc1.Bitmap.BitmapChanged;  // the original example said that this would redraw the image. In my CE Rio IDE the BitmapChanged is undefind. How can I use it?

Draw the line. IDE cannot find BitmapChanged.

2

There are 2 best solutions below

0
GreatDayDan On

BitmapChanged is a protected member. I need to write some code to handle the OnBitmapChanged event. I understand now. Almost 30 years of developing in Delphi and this is the first time I have run into protected members. The examples I was using must not have been compiled else the writer would have had the same error that I had.

0
Remy Lebeau On

TBitmap.BitmapChanged() is a virtual method that simply fires the public TBitmap.OnChange event. Since it is protected, you can use an accessor class to reach it:

type
  TBitmapAccess = class(TBitmap)
  end;

TBitmapAccess(imgc1.Bitmap).BitmapChanged;

However, this is not really needed. TImage assigns its own internal OnChange event handler to its Bitmap. So it should react to changes to the Bitmap automatically. But, if for some reason it does not, the correct way to refresh the TImage is to call its Repaint() method:

imgc1.Repaint;

Which is exactly what TImage's internal OnChange handler does:

constructor TImage.Create(AOwner: TComponent);
begin
  inherited;
  FBitmap := TBitmap.Create(0, 0);
  FBitmap.OnChange := DoBitmapChanged;
  ...
end;

procedure TImage.DoBitmapChanged(Sender: TObject);
begin
  Repaint;
  UpdateEffects;
end;