灰度图像转换为彩色

procedure GrayToColor(Bmp:TBitmap);

var

i,j,uG:integer;

begin

Bmp.PixelFormat:=pf24Bit;

for j:=0 to Bmp.Height-1 do

begin

p:=Bmp.Scanline[j];

for i:=0 to Bmp.Width-1 do

begin

uG:=p[3*i];

if (0<uG) and (uG<63) then

begin

p[3*i+2]:=0;

p[3*i+1]:=254-4*uG;

p[3*i]:=255;

end;

if (64<=uG) and (uG<127) then

begin

p[3*i+2]:=0;

p[3*i+1]:=4*uG-254;

p[3*i]:=510-4*uG;

end;

if (128<=uG) and (uG<191) then

begin

p[3*i+2]:=4*uG-510;

p[3*i+1]:=255;

p[3*i]:=0;

end;

if (192<=uG) and (uG<=255) then

begin

p[3*i+2]:=255;

p[3*i+1]:=1022-4*uG;

p[3*i]:=0;

end;

end;

end;

end;

原文地址:https://www.cnblogs.com/djcsch2001/p/2035847.html