Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: ratmalwer on January 19, 2022, 02:59:18 am

Title: How to inherit Events from a given TImage
Post by: ratmalwer on January 19, 2022, 02:59:18 am
I have a Form containing an Image.
this Image can be manipulated by events, like Mouse-up Mouse-down and so on.


For performanceissues I created an array of Images where I preformat the Image and its content (picture).
This array is loaded in the background.

Now when I load the Image the Picture is shown as expected, but the events on that image do not work anymore, as I pressume its because the Image works now as a pointer.

How can I inherit the Events to the displayed Image?

Here some codesnippeds:

Loop filling the Array:

Code: Pascal  [Select][+][-]
  1.          filelistPointer[i].Foto := TImage.Create(FormFotoAnzeige);  
  2.          filelistPointer[i].Foto.Parent := FormFotoAnzeige;
  3.          filelistPointer[i].Foto.top := 0;
  4.          filelistPointer[i].Foto.left := 0;
  5.          filelistPointer[i].Foto.width := 1920;
  6.          filelistPointer[i].Foto.height := 1080;
  7.          filelistPointer[i].Foto.Proportional:=True;
  8.          filelistPointer[i].Foto.Center:=True;
  9.          filelistPointer[i].Foto.stretch := true;
  10.          filelistPointer[i].Foto.StretchInEnabled:=true;
  11.          filelistPointer[i].Foto.StretchOutEnabled:=true;
  12.          filelistPointer[i].Foto.visible:=false;
  13.          filelistPointer[i].Foto.Picture.LoadFromFile(filelistPointer[i].Filename);

Reading the Image into my form

Code: Pascal  [Select][+][-]
  1.     ImageQuer.visible := false;
  2.     ImageQuer := filelistPointer[sgX.Row].Foto;
  3.     ImageQuer.visible := true;  
Title: Re: How to inherit Events from a given TImage
Post by: Jorg3000 on January 19, 2022, 04:08:10 am
Hi!
Instead of ImageQuer := filelistPointer[sgX.Row].Foto;
try this
Code: Pascal  [Select][+][-]
  1. ImageQuer.Picture.Assign( filelistPointer[sgX.Row].Foto.Picture );

This preserves ImageQuer (it must have been created before) and keeps all its properties, including the events.
Only the picture content is taken over.
Some previous assignments to filelistPointer[].Foto such as filelistPointer[].Foto.stretch:=true are then irrelevant.
Grüße, Jörg
Title: Re: How to inherit Events from a given TImage
Post by: ratmalwer on January 19, 2022, 05:18:34 am
Hi Jorg

I was suspecting, that my intention of preformatting does not work as I hoped.
Thanks for your answer - I will give it a try!
Title: Re: How to inherit Events from a given TImage
Post by: Handoko on January 19, 2022, 05:20:24 am
Or maybe:

Code: Pascal  [Select][+][-]
  1.   filelistPointer[sgX.Row].Foto.OnMouseUp := ImageQuer.OnMouseUp;
  2.   filelistPointer[sgX.Row].Foto.OnMouseDown  := ImageQuer.OnMouse;
  3.   ImageQuer := filelistPointer[sgX.Row].Foto;
  4.   ImageQuer.Visible := True;
Title: Re: How to inherit Events from a given TImage
Post by: ratmalwer on January 19, 2022, 05:51:33 am
Hi Handoko

ok...
I have a try on that as well - just for learning!

Meanwhile I found, that it makes no difference preloading the Image or just load the Picture itself into the Image of the Form.
The Main-Issue is the loadingtime (Loadfromfile) that takes some time (2 - 4 sec.) on large Images.
I had a try with gr32 and vampyre but it was not really much better  8) sometimes I even got some artefakte...

Thanks - I allways be glad for some help
Markus
Title: Re: How to inherit Events from a given TImage
Post by: Onur2x on January 23, 2022, 03:21:02 am
Code: Pascal  [Select][+][-]
  1. filelistPointer[i].Foto.OnMouseUp := @exampleimageMouseDown;
  2. filelistPointer[i].Foto.OnMouseDown  := @exampleimageMouseDown;
  3.  
  4. procedure TForm1.exampleimageMouseDown(Sender: TObject; Button: TMouseButton;
  5. Shift: TShiftState; X, Y: Integer);
  6. begin
  7.  ImageQuer.Picture.Assign(Timage(sender).picture);
  8.  ImageQuer.visible := true;
  9. end;
Title: Re: How to inherit Events from a given TImage
Post by: jamie on January 23, 2022, 03:19:47 pm
I found if you simply use a TGraphicsControl class and build some functionality around that and then simply set the parent of that control to lets say the Timage, you can capture all mouse control activity via that graphic control and even draw some lines on the image from that control if you wish. For example a rubber band selection box and still see all of the image it is covering.

 With that tactic you can set the events of the control only once etc.

TinyPortal © 2005-2018