Recent

Author Topic: [Solved] How can I use TBGRALayeredBitmap with multiple images in real time?  (Read 690 times)

loaded

  • Full Member
  • ***
  • Posts: 145
Hi All
I have 3 different image objects with a resolution of 1920x1080, I can layer them and at the same time, I can display each image with a transparency value specific to the following code.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   bgrabitmap, BGRABitmapTypes,BGRALayers,
  9.   Classes, SysUtils, Forms, Controls, Graphics,
  10.   Dialogs, StdCtrls, ExtCtrls, Menus, Buttons, ComCtrls;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     BitBtn1: TBitBtn;
  18.     Image1: TImage;
  19.     Image2: TImage;
  20.     Image3: TImage;
  21.     Render: TImage;
  22.     TrackBar1: TTrackBar;
  23.     TrackBar2: TTrackBar;
  24.     TrackBar3: TTrackBar;
  25.     procedure BitBtn1Click(Sender: TObject);
  26.     procedure TrackBar1Change(Sender: TObject);
  27.     function blayers:Boolean;
  28.  
  29.   private
  30.  
  31.   public
  32.  
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41.  
  42. { TForm1 }
  43.  
  44.  
  45. function btobgra(bt:TBitmap):Tbgrabitmap;
  46. var
  47.   br:Tbgrabitmap;
  48. begin
  49.   result:=Tbgrabitmap.Create(bt,false);
  50. end;
  51.  
  52. function  TForm1.blayers:Boolean;
  53. var
  54.  layer:TBGRALayeredBitmap;
  55. begin
  56.     try
  57.     render.Picture:=nil;
  58.     render.canvas.Brush.Color:=clWhite;
  59.     render.canvas.FillRect(render.Canvas.ClipRect);
  60.     layer:=TBGRALayeredBitmap.Create(render.Width,render.Height);
  61.     layer.AddLayer(btobgra(Image1.Picture.Bitmap),TrackBar1.Position);
  62.     layer.AddLayer(btobgra(Image2.Picture.Bitmap),TrackBar2.Position);
  63.     layer.AddLayer(btobgra(Image3.Picture.Bitmap),TrackBar3.Position);
  64.     layer.Draw(Render.canvas,0,0);
  65.     layer.Free;
  66.     result:=true;
  67.     except
  68.     result:=false;
  69.     end;
  70. end;
  71.  
  72.  
  73. procedure TForm1.BitBtn1Click(Sender: TObject);
  74.  var
  75.    cron:cardinal;
  76. begin
  77.   cron:=GetTickCount64;
  78.   if blayers then  TButton(sender).Caption:=floattostr((GetTickCount64-cron)/1000);
  79. end;
  80.  
  81. procedure TForm1.TrackBar1Change(Sender: TObject);
  82.  var
  83.    cron:cardinal;
  84. begin
  85.   cron:=GetTickCount64;
  86.   if blayers then  Form1.Caption:=floattostr((GetTickCount64-cron)/1000);
  87. end;
  88.  
  89.  
  90. end.
  91.  
  92.  
  93.  

I am making possible changes within the trackbar onchange procedure.
In the meantime, there is a delay in imaging.
What's more, the white screen issue arises in continuous use.
Then I have to close the program.

I would gladly listen if there are any suggestions and suggestions to be able to do the above process without any problem simultaneously with the change of trackbar position.
Respects.
« Last Edit: March 06, 2020, 12:31:57 pm by loaded »
Installing the spelling, google translate is used :)

circular

  • Hero Member
  • *****
  • Posts: 3645
    • Personal webpage
Re: How can I use TBGRALayeredBitmap with multiple images in real time?
« Reply #1 on: March 06, 2020, 10:46:53 am »
Hello

I suppose your code creates the layered image every time it is displayed.

You can instead create it once and then set the opacity on the fly with LayerOpacity property.

Also use AddOwnedLayer instead of AddLayer to avoid memory leak.

Regards
Conscience is the debugger of the mind

loaded

  • Full Member
  • ***
  • Posts: 145
Re: How can I use TBGRALayeredBitmap with multiple images in real time?
« Reply #2 on: March 06, 2020, 12:31:42 pm »
Mr. Circular , You’re a great help, i must say.
You made my job very easy.

I would like to ask one more thing that there may be another more useful thing to learn;
Is there any alternative method instead of the draw method?
Regards.
Installing the spelling, google translate is used :)

circular

  • Hero Member
  • *****
  • Posts: 3645
    • Personal webpage
You're welcome.

Instead of Draw you can call ComputeFlatImage to get the resulting image.

What else would you like to do?
Conscience is the debugger of the mind

loaded

  • Full Member
  • ***
  • Posts: 145
It was good that I learned the ComputeFlatImage method.

What else would you like to do?

What more, thanks to you, I solved my problem.
Installing the spelling, google translate is used :)

circular

  • Hero Member
  • *****
  • Posts: 3645
    • Personal webpage
Ok   :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018