Forum > Windows

Drawing a Buffer on a Canvas

(1/1)

Key-Real:
How to draw a Buffer on a Canvas?


  for y:=0 to height-1 do
      for x:=0 to width-1 do begin
        gfxCanvas.pixels[x,y]:=getPixel(bitmap,x,y);
      end; 

is to slow...

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

Handoko:
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:
https://forum.lazarus.freepascal.org/index.php/topic,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.
https://wiki.freepascal.org/Portal:HowTo_Demos#Graphics

lucamar:
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. ;)

wp:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- gfxCanas.Draw(0, 0, bitmap);

Navigation

[0] Message Index

Go to full version