Acces to pixels
types of acces to pixels in delphi
- using Pixels property ( simple but slow)
- raster scan 1 pass with 2 loops
procedure TForm1.Draw1Click(Sender: TObject);
const _width=500; // give that name because "width" means form1.width
_height=500;
var x,y:integer;
begin
for y:=0 to (_height-1) do
for x:=0 to (_width-1) do
form1.Canvas.Pixels[x,y]:=rgb(1,1,1);
end;
- raster scan 1 pass with 1 loop:
Procedure ...
const _width=500; // give that name because "width" means form1.width
_height=500;
PixelNumberMax= _height*_width;
var iX,iY:integer;
PixelNumber:integer;
begin
for PixelNumber:=0 to (PixelNumberMax-1) do
begin
iX:=0+(PixelNumber mod _width);
iY:=0+(PixelNumber div _width);
form1.Canvas.Pixels[iX,iY]:=rgb(0,0,0);
end; // for pixelNumber ...
end; // procedure ...
- using ScanLine ( more lines to write but very fast)
- GetDIBits Function
Requirements :
Header Wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll
example from Andrew Rybenkov
where put the drawing code ?
- in the OnCreate procedure
- in the OnPaint procedure
- in the procedure of OnClick of menu item
method of drawing:
- directly on canvas of the form
- on off-screen bitmap ( it is not seen) and after the drawing display bitmap on the image of the form
How to clear memeory bitmap:
procedure TForm1.Clear1Click(Sender: TObject);
var iX,iY:integer;
begin
FirstLine := bitmap.Scanline[0];
LineLength := (Longint(bitmap.Scanline[1]) - Longint(FirstLine)) div SizeOf(TRGB32);
// clear all points of the bitmap
for iX:=iXmin to iXmax do
For iY :=iYmin to iYMax do
with FirstLine[iY*LineLength+iX] do
begin // all points white
B := 255;
G := 255;
R := 255;
//A := 0;
end;
// display new = blank, white bitmap
Image1.Picture.Graphic:=bitmap;
end;
Main Page
Feel free to e-mail me!
Author: Adam Majewski adammaj1-at-o2-dot-pl
About
http://republika.pl/fraktal/