【问题标题】:RGBApixel’ has no member named...red blue and greenRGBApixel' 没有名为...red blue and green 的成员
【发布时间】:2014-10-08 18:16:06
【问题描述】:

我收到多个错误,说明“'RGBApixel' 没有名为 'red' 的成员”、“'RGBApixel' 没有名为 'green' 的成员,以及“'RGBApixel' 没有名为 'blue' 的成员”。不知道为什么,因为我使用的是 EasyBMP 库。

在下面的函数中,我在 BMP 图像中定位一个像素,然后将该像素的 rgb 值与 color1 和 color2 rgb 值进行比较。像素将变为最接近它的颜色:

BMP Preprocessor (BMP pix, RGBApixel color1, RGBApixel color2, int xlow, int xhigh, int ylow, int yhigh){

  for (int i = xlow; i < xhigh; i++){
    for (int j = ylow; j < yhigh; j++){

      RGBApixel pixel = pix.GetPixel(i,j);

      double distance1 = abs(pixel.red - color1.red) + abs(pixel.green - color1.green) + abs(pixel.blue - color1.blue);

      double distance2 = abs(pixel.red - color2.red) + abs(pixel.green - color2.green) + abs(pixel.blue - color2.blue);

      if (distance1 < distance2) { // pixel color closest to color1
        pixel.red = color1.red;
        pixel.green = color1.green;
        pixel.blue = color1.blue;

      }  
      else { // pixel color closest to color2
        pixel.red = color2.red;
        pixel.green = color2.green;
        pixel.blue = color2.blue;
      }
    }
  }
  return pix;
}

【问题讨论】:

标签: c++ rgb pixels bmp rgba


【解决方案1】:

我在 easybmp.sourceforge.net 上找到了这个代码示例:

RGBApixel FontColor;
FontColor.Red = 255; FontColor.Green = 0; FontColor.Blue = 0;

因此,“Red”、“Green”和“Blue”成员似乎使用大写字母,而在您的代码中,您尝试使用小写字母访问它们。所以你的编译器是对的,你试图访问的成员不存在。

只需将访问成员的行从pixel.red 等更改为pixel.Red

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多