procedure ColToAverageGrey( const BMP : TBitmap );
var Grey : Byte;
i : Integer;
Pix : pRGBQuad;
begin
BMP.PixelFormat := pf32bit;
Pix := BMP.ScanLine[ BMP.Height-1 ]; // Un seul appel à Scanline.
for i:=1 to BMP.Width*BMP.Height do begin
Grey := ( Pix^.rgbBlue + Pix^.rgbGreen + Pix^.rgbRed ) div 3;
Pix^.rgbBlue := Grey;
Pix^.rgbGreen := Grey;
Pix^.rgbRed := Grey;
Inc( Pix );
end;
end;
procedure ColToSightGrey( const BMP : TBitmap );
var Grey : Byte;
i : Integer;
Pix : pRGBQuad;
begin
BMP.PixelFormat := pf32bit;
Pix := BMP.ScanLine[ BMP.Height-1 ]; // Un seul appel à Scanline.
for i:=1 to BMP.Width*BMP.Height do begin
Grey := round( Pix^.rgbBlue*0.0721 + Pix^.rgbGreen*0.7154 + Pix^.rgbRed*0.2125 );
Pix^.rgbBlue := Grey;
Pix^.rgbGreen := Grey;
Pix^.rgbRed := Grey;
Inc( Pix );
end;
end;
{UTILISATION :}
procedure TForm1.Button1Click( Sender: TObject );
var BMPtemp1, BMPtemp2 : TBitmap;
begin
BMPtemp1 := TBitmap.Create;
BMPtemp2 := TBitmap.Create;
try
BMPtemp1.Assign( Image1.picture.bitmap );
ColToAverageGrey( BMPtemp1 );
Image2.Picture.Bitmap.Assign( BMPtemp1 );
BMPtemp2.Assign( Image1.picture.bitmap );
ColToSightGrey( BMPtemp2 );
Image3.Picture.Bitmap.Assign( BMPtemp2 );
finally BMPtemp2.Free;BMPtemp1.Free; end;
end;