2014-10-08 57 views
-1

我收到多个错误,指出''RGBApixel'没有名为'red'的成员'',''RGBApixel'没有名为'green'的成员,并且“'RGBApixel'没有名为'blue'的成员不知道为什么,因为我使用EasyBMP库RGBApixel'没有成员名为...红色蓝色和绿色

在下面的函数中,我在BMP图像中找到一个像素,然后比较该像素的rgb值。颜色1和颜色2的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; 
} 
+0

你是如何包括图书馆的标题? – Jason 2014-10-08 18:18:05

+0

你能告诉我们RGBApixel的定义吗? – 2014-10-08 18:18:51

+0

#include“EasyBMP.h” – user2044600 2014-10-08 18:19:59

回答

2

我发现easybmp.sourceforge.net此代码示例:

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

因此,'红色','绿色'和'蓝色'成员似乎使用大写字母,而在您的代码中,您试图使用小写字母访问它们。所以你的编译器是正确的,你试图访问的成员不存在。

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

+0

这就是我在手册中看到的。 – user3344003 2014-10-08 18:24:51

相关问题