图像亮度调节的问题(100分)

  • 主题发起人 主题发起人 wzgss
  • 开始时间 开始时间
W

wzgss

Unregistered / Unconfirmed
GUEST, unregistred user!
我试验代码如下:
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;
语句:pRGB.R := ColorTable[pRGB.R].R;这个就出错,高手回答。如果邮寄给我完整的调试好的程序,100分奉上。songshuang@163.com
 
给你一代码,已经调通的。
function brightness(dest:tbitmap;t:shortint):tbitmap;
var
x,y:word;
line:PByteArray;
begin
if dest.PixelFormat<>pf24bit then dest.PixelFormat:=pf24bit;
for y:=0 to dest.Height-1 do
begin
line:=PByteArray(dest.scanline[y]);
for x :=0 to dest.Width -1 do
begin
line[x*3+2]:= bound(t + line[x*3+2]);
line[x*3+1]:= bound(t + line[x*3+1]);
line[x*3]:= bound(t + line[x*3]);
end;
end;
result:=dest;
end;
 
To chen_cch:bound是你的函数吗?我用的是d5
 
不好意思,我给望了。
function bound(x:integer):Byte;
begin
if x>255 then x:=255;
if x<0 then x:=0;
bound:=Byte(x);
end;
 
function bound(dd:integer):integer;
begin
Result:=dd;
if dd>255 then
Result:=255
else
if dd<0 then
Result:=0;
end;
哈哈,谢谢
 
接受答案了.
 
后退
顶部