Recent

Author Topic: I need help with BeginUpdate and EndUpdate  (Read 2035 times)

stem

  • Jr. Member
  • **
  • Posts: 88
I need help with BeginUpdate and EndUpdate
« on: February 09, 2020, 03:25:52 pm »
Hi,

I have a procedure which gets a TImage object (myImage) as parameter and calculates some colors. The colors get stored with

Code: Pascal  [Select][+][-]
  1. myImage.canvas.Pixels[col, row] := myColor;

Everything works fine. To speed up the calculation, I've put everything in try and finally together with BeginUpdate() and EndUpdate():

Code: Pascal  [Select][+][-]
  1. try
  2.   myImage.Picture.Bitmap.BeginUpdate();
  3.   ... (my code)
  4. finally
  5.   myImage.Picture.Bitmap.EndUpdate();
  6. end;
  7.  

Unfortunately this stops painting the image completely. If I comment out the two lines with BeginUpdate() and EndUpdate(), everything works again.

What am I doing wrong?

Thank you.

stem

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: I need help with BeginUpdate and EndUpdate
« Reply #1 on: February 09, 2020, 03:40:22 pm »
myImage.Canvas is the surface of the control, which gets replaced on repaint.

If you want the pixels to stay in the image you would rather use myImage.Picture.Bitmap.Canvas.

Note that the Bitmap size must be set up correctly.
Conscience is the debugger of the mind

stem

  • Jr. Member
  • **
  • Posts: 88
Re: I need help with BeginUpdate and EndUpdate
« Reply #2 on: February 09, 2020, 04:09:21 pm »
If you want the pixels to stay in the image you would rather use myImage.Picture.Bitmap.Canvas.
Note that the Bitmap size must be set up correctly.

I replaced my code the way you suggested. The image gets correctly painted with myImage.Picture.Bitmap.Canvas, but only (again) if I comment out the two lines with BeginUpdate() and EndUpdate() ...

If the two lines are active, the image is completely black.

stem

balazsszekely

  • Guest
Re: I need help with BeginUpdate and EndUpdate
« Reply #3 on: February 09, 2020, 05:41:04 pm »
Set myimage width and height to 500, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   with MyImage.Picture.Bitmap do
  4.   begin
  5.     SetSize(500, 500);
  6.     BeginUpdate(True);
  7.     try
  8.       Canvas.Pen.Color := clRed;
  9.       Canvas.Line(0, 0, 500, 500);
  10.       Canvas.Line(500, 0, 0, 500);
  11.     finally
  12.       EndUpdate;
  13.     end;
  14.   end;
  15. end;  

stem

  • Jr. Member
  • **
  • Posts: 88
Re: I need help with BeginUpdate and EndUpdate
« Reply #4 on: February 09, 2020, 10:30:00 pm »
Thank you!

 

TinyPortal © 2005-2018