AddConvert a colour bitmap to greyscale
IRatio and CRatio adjust the intensity and contrast.

  1. type
  2.   TRGB = record
  3.     B : byte;
  4.     G : byte;
  5.     R : byte;
  6.   end;
  7.   TRGBArray = array[0..32767] of TRGB;
  8.   PRGBArray = ^TRGBArray;
  9.  
  10. // convert a colour bitmap to greyscale
  11. procedure GreyscaleBitmap(ABitmap : TBitmap ; IRatio, CRatio : Single);
  12. Var
  13.   LRow : PRGBArray;
  14.   Lx, Ly, LI, LRowBytes : integer;
  15.   LIF : Single;
  16. begin
  17.   LRow := ABitmap.Scanline[0];
  18.   LRowBytes := Integer(ABitmap.Scanline[1]) - Integer(LRow);
  19.   for Ly := 0 to ABitmap.Height - 1 do begin
  20.     for Lx := 0 to ABitmap.Width - 1 do begin
  21.       LIF := 0.3*LRow[Lx].R + 0.59*LRow[Lx].G + 0.11*LRow[Lx].B;
  22.       LIF := 128 + CRatio*(LIF - 128);
  23.       LI := Round(LIF * IRatio);
  24.       if LI > 255 then LI := 255;
  25.       LRow[Lx].B := LI;
  26.       LRow[Lx].G := LI;
  27.       LRow[Lx].R := LI;
  28.     end;
  29.     Inc(Integer(LRow), LRowBytes);
  30.   end;
  31. end;
  • Author:
  • URL:
    http://www.geocities.com/peter_bone_uk
  • Date added:
    03 March, 2006
  • Views:
    6245
Latest News
Submit News Form Past News
Latest Forum Entries