私の画像クラスでは、画像に渡された後にピクセルを変更したいのですが、それでも画像を変更する必要があります。
int main(int argc, char* argv[]){
Image theImage(4, 8);//width/height
Pixel aPixel(2,1);
Pixel* p = &aPixel;
theImage.setPixel(p);
aPixel.setBlue(100);//change the blue (RGB) value of the pixel, but Pixel color doesnt change
theImage.saveAsPixelMap("/Users/dan/Desktop/test.ppm");
return 0;
}
Imageclassがポインタを保持しているので、Pixelの色が変わると思いましたが、ポインタが同じPixelを指している場合、どのColorが変更されても、ImageのPixelの色は変更されるべきではありませんか?
Pixelコンストラクタは次のとおりです。
Pixel::Pixel(int tx, int ty){
red = 255;
green = 0;
blue = 0;
x = tx;
y = ty;
hasBeenChanged = false;
}
およびsetPixelメソッド
void Image::setPixel(Pixel *aPixel){
int tX = aPixel->getX();
int tY = aPixel->getY();
imageData.at(tY).at(tX)->setRed(aPixel->getRed());//value 0 - 255
imageData.at(tY).at(tX)->setGreen(aPixel->getGreen());
imageData.at(tY).at(tX)->setBlue(aPixel->getBlue());
}
imageDataは次のようになります
std::vector< std::vector<Pixel*> > imageData;
およびsaveAsPixelmapメソッド。
void Image::saveAsPixelMap(char aPath[]){
std::ofstream myfile;
myfile.open(aPath);
myfile << "P3\n" << this->getWidth() <<" "<< this->getHeight() <<"\n255\n";
std::vector < Pixel* > row;
for (int y = 0; y < this->getHeight(); y++){
row = imageData.at(y);
for (int x = 0; x < this->getWidth(); x++){
myfile << row.at(x)->getRed() << " ";
myfile << row.at(x)->getGreen() << " ";
myfile << row.at(x)->getBlue() << " ";
std::cout <<"rot: "<< imageData.at(y).at(x)->getRed();
}
}
std::cout << "\n Writing File to " << aPath << "\n \n";
myfile.close();
}
わかりました、それはたくさんのコードです、あなたが何かについてより多くの情報を必要とするか、私の質問が十分に明確でないかどうか私に尋ねてください。これを解決するためのヒントはありがたいです