Author Topic: Drawing a Buffer on a Canvas  (Read 3604 times)


  • Full Member
  • ***
  • Posts: 169
Drawing a Buffer on a Canvas
« on: April 30, 2021, 07:10:39 pm »
How to draw a Buffer on a Canvas?

  for y:=0 to height-1 do
      for x:=0 to width-1 do begin

is to slow...

ia there a fast way like move(,, width*height);  <- as Idea


  • Hero Member
  • *****
  • Posts: 5061
  • My goal: build my own game engine using Lazarus
Re: Drawing a Buffer on a Canvas
« Reply #1 on: April 30, 2021, 08:50:40 pm »
Don't use TCanvas, it is slow.

Almost all VGAs even those 20 years old integrated VGAs have some basic support of hardware accelerated OpenGL. Performing graphics using hardware accelerated functions is not only twice or thrice faster than the non-hardware accelerated TCanvas but it can be hundreds times faster or more.
Read more:,51687.msg379944.html#msg379944

But if you don't have time to learn a new framework, use ScanLine. It will point you to the address of a horizontal line of pixels, this works much faster.

In the link below there is a "Get pixel color of an image" demo showing how to use ScanLine.


  • Hero Member
  • *****
  • Posts: 4219
Re: Drawing a Buffer on a Canvas
« Reply #2 on: April 30, 2021, 10:18:42 pm »
Note also that if your "bitmap" is some kind of TGraphic descendant, TCanvas has quite a lot of ways of drawing it or making it draw itself: CopyRect, Draw, StretchDraw, etc. most of which are usually "fast enough".

There's no need of copying it pixel by pixel. ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.


  • Hero Member
  • *****
  • Posts: 11482
Re: Drawing a Buffer on a Canvas
« Reply #3 on: April 30, 2021, 10:54:03 pm »
Why do we always have to guess so many details?

Assuming that gfxCanvas is a TCanvas and bitmap is a TBitmap or another descendant of TGraphic then this works:

Code: Pascal  [Select][+][-]
  1.  gfxCanas.Draw(0, 0, bitmap);


TinyPortal © 2005-2018