canvas - Delphi How to draw 2d array of TColor on TCanvas quickly? -


i have 2-dimensional array of tcolor. , have tcanvas. how can draw color map on canvas faster for cycle?

for example:

type   t2dar = array of array of tcolor;  var   ar: t2dar;   form1: tform; // mainform  function main; var x, y: integer; begin {filling array colors 10x10}  x := 0 length(ar)-1 y := 0 length(ar[x])-1 form1.canvas.pixels[x, y] := ar[x, y]; end; 

this way works slowly. need faster algorithm.

this has been answered many times. answer is: use scanlines instead of terribly slow pixels property. example:

function createbitmapreallyfast: tbitmap; const   white: trgbtriple = (rgbtblue: 255; rgbtgreen: 255; rgbtred: 255);   black: trgbtriple = (rgbtblue: 0; rgbtgreen: 0; rgbtred: 0); var   y: integer;   scanline: prgbtriple;   x: integer; begin   result := tbitmap.create;   result.setsize(1920, 1080);   result.pixelformat := pf24bit;   y := 0 result.height - 1   begin     scanline := result.scanline[y];     x := 0 result.width - 1     begin       if odd(x)         scanline^ := white       else         scanline^ := black;       inc(scanline);     end;   end; end; 

even cooler:

with scanline^ begin   rgbtblue := random(255);   rgbtgreen := random(255);   rgbtred := random(255); end; 

to try it:

procedure tform1.formpaint(sender: tobject); var   bm: tbitmap; begin   bm := createbitmapreallyfast;   try     canvas.draw(0, 0, bm);       bm.free;   end; end; 

of course, if have (packed) array of trgbtriple or trgbquad, , pixel format of bitmap same, can move data in memory array bitmap's scanlines.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -