如果是bmp位图,24色 procedure GrayBmp24(bmp: TBitmap); var btGray: Byte; nRow, nCol: integer; pRGB: pRGBTriple; begin if bmp.PixelFormat = pf24bit then begin for nRow := 0 to bmp.Height - 1 do begin pRGB := bmp.ScanLine[nRow]; for nCol := 0 to bmp.Width -1 do begin btGray := (77*pRGB^.rgbtRed + 151*pRGB^.rgbtGreen + 28*pRGB^.rgbtBlue) shr 8; pRGB^.rgbtBlue := btGray; pRGB^.rgbtGreen := btGray; pRGB^.rgbtRed := btGray; Inc(pRGB); end; end; end else begin bmp.PixelFormat := pf24bit; GrayBmp24(bmp); end; end;
procedure GrayBmp24(bmp: TBitmap);
var
btGray: Byte;
nRow, nCol: integer;
pRGB: pRGBTriple;
begin
if bmp.PixelFormat = pf24bit then
begin
for nRow := 0 to bmp.Height - 1 do
begin
pRGB := bmp.ScanLine[nRow];
for nCol := 0 to bmp.Width -1 do
begin
btGray := (77*pRGB^.rgbtRed + 151*pRGB^.rgbtGreen +
28*pRGB^.rgbtBlue) shr 8;
pRGB^.rgbtBlue := btGray;
pRGB^.rgbtGreen := btGray;
pRGB^.rgbtRed := btGray;
Inc(pRGB);
end;
end;
end
else
begin
bmp.PixelFormat := pf24bit;
GrayBmp24(bmp);
end;
end;