试试这个:
type
TRGBcolor=record
R,G,B:byte;
end;
pRGBcolor:=^Trgbcolor;
procedure Contrast(var Bmp: TBitmap; Amount: Integer);
// Amount: -255~255
var
X, Y: Integer;
I: Byte;
ColorTable: array[0..255] of TRGBColor;
pRGB: PRGBColor;
begin
for I := 0 to 126 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable.r := GetRValue(Byte(I - Y));
ColorTable.g := GetGValue(Byte(I - Y));
ColorTable.b := GetBValue(Byte(I - Y));
end;
for I := 127 to 255 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable.r := GetRValue(Byte(I + Y));
ColorTable.g := GetGValue(Byte(I + Y));
ColorTable.b := GetBValue(Byte(I + Y));
end;
for Y := 0 to Bmp.Height - 1 do
begin
pRGB := Bmp.ScanLine[Y];
for X := 0 to Bmp.Width - 1 do
begin
pRGB.R := ColorTable[pRGB.R].R;
pRGB.G := ColorTable[pRGB.G].G;
pRGB.B := ColorTable[pRGB.B].B;
Inc(pRGB);
end;
end;
end;