摘自以前的贴字
来自:xWolf
时间:99-12-14 13:06:00
ID:168381
控件的没有, 由几个函数希望能帮上你的忙.
TRGBColor = record R, G, B: Byte; end;
PRGBColor = ^TRGBColor;
// Bitmap.ScanLine[X] 可以获取图像象素的内存地址,24Bits的Bitmap的每一象
// 素是以三原色RGB的次序存放的,改变RGB的值就可调节Bitmap的色彩.
// R, G, B: -255~255
procedure RGB(var Bmp: TBitmap; R, G, B: Integer);
var
X, Y: Integer;
I: Byte;
ColorTable: array[0..255] of TRGBColor
pRGB: PRGBColor;
begin
for I := 0 to 255 do
begin
ColorTable.R := IntToByte(I + R);
ColorTable.G := IntToByte(I + G);
ColorTable.B := IntToByte(I + B);
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;
end;
Inc(pRGB);
end;
end;
// 改变图像的亮度,也只需调用RGB(Bmp, X, X, X)改变三原色.
来自:xWolf
时间:99-12-14 13:24:17
ID:168389
// 调节Bitmap的对比度
// 应用公式: 新颜色值 = (旧颜色值 - 128) * 系数 + 128
procedure Contrast(var Bmp: TBitmap; Amount: Integer);
// Amount: -255~255
var // The Same as procedure RGB
begin
for I := 0 to 126 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable := IntToByte(I - Y);
end;
for I := 127 to 255 do
begin
Y := (Abs(128 - I) * Amount) div 256;
ColorTable := IntToByte(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;
// 改变饱和度
procedure Saturation(var Bmp: TBitmap; Amount: Integer); // Amount: 0~510
var
Grays: array[0..767] of Integer;
Alpaha: array[0..255] of Word;
Gray, X, Y: Integer;
pGRB: PRGBColor;
I: Byte;
begin
for I := 0 to 255 do Alpha := (I * Amount) shr 8;
x := 0;
for I := 0 to 255 do
begin
Gray := I - Alpha;
Grays[X] := Gray; Inc(X);
Grays[X] := Gray; Inc(X);
Grays[X] := Gray; Inc(X);
end;
for Y := 0 to Bmp.Height - 1 do
begin
pRGB := Bmp.ScanLine[Y];
for X := 0 to Bmp.Width - 1 do
begin
Gray := Grays[pRGB.R + pRGB.G + pRGB.B];
pRGB.R := IntToByte(Gray + Alpha[RGB.R]);
pRGB.G := IntToByte(Gray + Alpha[RGB.G]);
pRGB.B := IntToByte(Gray + Alpha[RGB.B]);
Inc(pRGB);
end;
end;
end;