-1

I am working cross platform vnc project. Windows side is ok with VCL. But when i use FMX platform with same code, i having problems.

procedure TFrmScreenView.pbViewPaint(Sender: TObject);
begin
  Client.DrawBitmap(pbView.Canvas);
end;

This code is updating to Paintbox Canvas for every new image packet from remote computer. This working on VCL no problem. But when i execute this project on FMX image repaint is not working. It just gets the first image and it doesn't update.

procedure TFrmScreenView.pbViewPaint(Sender: TObject; Canvas: TCanvas);
begin
  Client.DrawBitmap(pbView.Canvas);
end; 

Client Code:

procedure TClient.DrawBitmap(Canvas: TCanvas);
  begin
  if assigned(Bitmap) then // Bitmap is global variable
    begin
    Canvas.DrawBitmap(Bitmap,RectF(0,0,Bitmap.Width, Bitmap.Height),
                             RectF(0,0,Bitmap.Width, Bitmap.Height),1,True);
    end;
  end;

If i use timer paintbox is updateing for every image package

procedure TScreenViewFrm.Timer1Timer(Sender: TObject);
begin
  pbScreenView.Repaint;
end;

I have to use Timer for repaint on my code but i dont want this and not working stable.

***Note: When i resize ScreenView form Paint box is updating. Why?

Do you have any idea?

Example Capture

https://gyazo.com/f880c2f172b0106122ea711389bf1659

Aras
  • 1
  • 3

2 Answers2

0

After Client (I presume that is the packet receiver) has received a new image and it is stored in global Bitmap, do what you now do in the timer: pbScreenView.Repaint; (and remove the timer)

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • Yeah. I've tried but not working. Interesting, i debugged my code and i looked PaintBox.Paint method data comes instantly but not repaint to the paintbox. And why repaint on form resize? I dont understand. – Aras Aug 19 '20 at 13:31
  • How about providing a [mre]. Such that the receival of an image can be simulated with a button. Form resize triggers an update of all components on the form. – Tom Brunberg Aug 19 '20 at 13:36
  • It is illogical that a repaint triggered by a timer would work but not a repaint called in code – Tom Brunberg Aug 19 '20 at 13:39
  • Thanks Tom for help.I need to focus more.I guess it seems to be related to Threading.I dont need to call Repaint because i m already triggered like this on my socket on received pbScreenViewPaint(pbScreenView, pbScreenView.Canvas ); // or nil . I'll look. Thanks again. – Aras Aug 19 '20 at 14:42
0

When drawing anything to a canvas in FMX you must use TCanvas.BeginScene and finish with TCanvas.EndScene, otherwise nothing will get drawn.

procedure TClient.DrawBitmap(Canvas: TCanvas);
  begin
    if assigned(Bitmap) then // Bitmap is global variable
    begin
      if Canvas.BeginScene then begin
        try
          Canvas.DrawBitmap(Bitmap,Bitmap.Bounds,Bitmap.Bounds,1,True);
        finally
          Canvas.EndScene;
        end;
      end;
    end;
  end;
XylemFlow
  • 963
  • 5
  • 12