TCanvas: slow copying performance (simple animation) lazarus / 39-Graphics ---------------------------------------------------------------------- frett · 2012-09-05 16:29 Hi there, I've written a simple marquee text class for delphi some time ago, which I recently ported to lazarus along with the project using it. I encountered almost no problems, however, the cpu utilization of the marquee animation increased by a factor of 100: compiling with delphi 2006 and executing the application, the task manager always shows 0%, whereas the lazarus-compiled version consumes between 15% and 50% of the cpu (enabling optimizations has no effect). The class works as follows: a text line is drawn to an off-screen TBitmap, and then the appropriate rectangle section of this bitmap (depending on the current position of the animation) is copied to a TPaintBox canvas by a repeated Timer event that also advances the position counter. This is the method used for copying: Code: [Select]procedure TMarqueeText.CopySection(x1, y1, x2, y2: Integer; source: TCanvas;   destX, destY: Integer; dest: TCanvas); var   sourceRect, destRect: TRect; begin   sourceRect := Rect(x1, y1, x2, y2);   destRect := Rect(destX, destY, destX+(x2-x1), destY+(y2-y1));   dest.CopyRect(destRect, source, sourceRect); end; It seems that the TCanvas.Draw and CopyRect methods are very slow compared to their VCL counterparts (at least in this particular case). I wonder what I'm doing wrong here, simply copying an image portion to another canvas can't be that expensive... Development system: WinXP SP3, Lazarus 1.0 ---------------------------------------------------------------------- TurboRascal · 2012-09-06 19:35 Perhaps you could draw to a TBitmap and use this instead: Code: [Select]Canvas.Draw(x, y, Bitmap) Among the examples that came with Lazarus there is a nice one in the 'sprites' subdirectory which uses something similar to create a smooth animation. ---------------------------------------------------------------------- frett · 2012-09-06 22:02 I have tried that (Canvas.Draw) too, but it seems to be equally slow. Nevertheless, thank you for the hint on the sprites example, I'll have a look at it.