加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 获取图像的平均颜色

发布时间:2020-12-15 09:31:15 所属栏目:大数据 来源:网络整理
导读:我想要获得图像的平均颜色.我尝试了各种方法,现在我使用以下代码,但我无法得到正确的结果. 任何人都可以解释我的代码有什么问题吗? //load bitmap to curimg img1.Picture.Bitmap := curimg ; //testing the previous line //My image is always greater th
我想要获得图像的平均颜色.我尝试了各种方法,现在我使用以下代码,但我无法得到正确的结果.

任何人都可以解释我的代码有什么问题吗?

//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;

我的表格中包含TImageBox类型的img1和image1.

解决方法

局部变量r,b:integer应首先初始化为零.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读