views:

133

answers:

2

Context

I am drawing to a canvas, this is updated regularly and it flashes. Logically thinking I assumed this is because my redraw method clears the Canvas then draws one element at a time to the canvas. so my idea was to write to a Timage then set the picture to the Timage.


Information

here is my code

procedure Tmainwindow.Button3Click(Sender: TObject);
var bufferpicture:TImage;
begin

//draw stuff to bufferpicture
  //***
//draw stuff to bufferpicture

myrealpicture.picture:=bufferpicture.picture;

end;

Upon running the code I get a error show below. alt text


Question How do I set the canvas of one to another since canvas is a read only property? or is there a better way to do what i am trying to do?

+3  A: 

use the DoubleBuffered property

splash
+5  A: 
  1. It looks like you did not create myrealpicture
  2. I would use the method Assign

    MyRealPicture.Picture.Assign(BufferPicture.Picture);

  3. You can copy the content of one canvas to another using BitBlt:

    var
      BackBuffer: TBitmap;
    begin
      BackBuffer := TBitmap.Create;
      try
        { drawing stuff goes here}
        BitBlt(Form1.Canvas.Handle, 0, 0, BackBuffer.Width, BackBuffer.Height,
            BackBuffer.Canvas.Handle, 0, 0, SRCCOPY);
      finally
        BackBuffer.Free;
      end;
    end;
    
  4. You can just use the DoubleBuffered property

bepe4711