我正在尝试获取图像的平均颜色。我尝试了各种方法,现在使用以下代码,但无法得到正确的结果。
谁能解释一下我的代码有什么问题吗?
//load bitmap to curimg
img1.Picture.Bitmap := curimg ; //testing the previous line
//My image is always greater than 25x25 but I only need a 25x25 box
for I := 0 to 25 do
begin
for y := 0 to 25 do
begin
r := r + GetRValue(curimg.Canvas.Pixels[y, I]);
g := g + GetGValue(curimg.Canvas.Pixels[y, I]);
b := b + GetBValue(curimg.Canvas.Pixels[y, I]);
end;
end;
r := r div (25 * 25);
g := g div (25 * 25);
b := b div (25 * 25);
rgbk := RGB(r, g, b);
Result = rgbk;
end;
img1
和 TImageBox
类型的 image1
在我的表单上。
最佳答案
局部变量r,g,b:整数
应首先初始化为零。
关于delphi - 获取图像的平均颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7722281/