在Image里面放一张bmp图var i,j:integer; sum:integer; r,g,b:integer; begin with Image1 do begin sum:=Picture.Width*Picture.Height; r:=0;g:=0;b:=0; for i:=0 to Picture.Width-1 do for j:=0 to Picture.Height-1 do begin r:=r+GetRValue(Canvas.Pixels[i,j]); g:=g+GetGValue(Canvas.Pixels[i,j]); b:=b+GetBValue(Canvas.Pixels[i,j]); end; end; r:=r div sum; g:=g div sum; b:=b div sum; Form1.Color:=rgb(r,g,b); ShowMessage(Format('%d %d %d',[r,g,b])); end;
然后分别除以点的个数?
获取R、G、B值: GetRValue、GetGValue、GetBValue
sum:integer;
r,g,b:integer;
begin
with Image1 do
begin
sum:=Picture.Width*Picture.Height;
r:=0;g:=0;b:=0;
for i:=0 to Picture.Width-1 do
for j:=0 to Picture.Height-1 do
begin
r:=r+GetRValue(Canvas.Pixels[i,j]);
g:=g+GetGValue(Canvas.Pixels[i,j]);
b:=b+GetBValue(Canvas.Pixels[i,j]);
end;
end;
r:=r div sum;
g:=g div sum;
b:=b div sum;
Form1.Color:=rgb(r,g,b);
ShowMessage(Format('%d %d %d',[r,g,b]));
end;