我正在编写一个读取ppm文件的代码,并将文件的宽度,高度和像素存储到图像对象中。在我的图像类中,我有一个包含图像数据的指针。我在设置x,y像素的rgb值的方法中也有错误。
typedef load compontent_t
class Image
{
public:
enum channel_t { RED = 0, GREEN, BLUE };
protected:
component_t * buffer; //! Holds the image data.
unsigned int width, //! The width of the image (in pixels)
height; //! The height of the image (in pixels)
// data mutators
/*! Sets the RGB values for an (x,y) pixel.
*
* The method should perform any necessary bounds checking.
*
* \param x is the (zero-based) horizontal index of the pixel to set.
* \param y is the (zero-based) vertical index of the pixel to set.
* \param value is the new color for the (x,y) pixel.
*/
void setPixel(unsigned int x, unsigned int y, Color & value) {
if (x > 0 && x < width && y > 0 && y < height) {
size_t locpixel = y*width + x;
size_t componentofpixel = locpixel * 3;
*buffer + componentofpixel = value.r;
*buffer + componentofpixel + 1 = value.g;
*buffer + componentofpixel + 2 = value.b;
}
else {
cout << "Pixel out of bounds" << endl;
}
}
Image(unsigned int width, unsigned int height, component_t * data_ptr): width(width), height(height),buffer(data_ptr) {}
所以在setPixel方法中,当我试图找到缓冲区的正确位置来设置rgb值时,它会向我显示错误:&#34;表达式必须是可修改的L值&#34;