ofImage.setPixel not working?

  
  
image = ofImage("0.PNG");  
	  
res = ofImage();  
res.width = image.getWidth();  
res.height = image.getHeight();  
  
for (int x = 0; x < image.getWidth(); x++) {  
	for (int y = 0; y < image.getHeight(); y++) {  
		res.setColor(x, y, ofColor::white);  
		if (image.getColor(x, y) != ofColor::white) {  
			res.setColor(x, y, ofColor(0, 0, 0));  
			cout << ofColor(0, 0, 0).getHex() << ", " << res.getColor(x, y).getHex() << "\n";  
		}  
	}  
}  
  

[tt]0.PNG[/tt] is an image with white and black parts.

If there’s any [tt]cout[/tt] output then it should output [tt]0, 0[/tt], but instead it’s outputting [tt]0, 16777216[/tt], which suggests that the previous [tt]res.setColor()[/tt] is not working.

How should I fix this code?

I think you need to call allocate:

  
  
res.allocate(image.getWidth(), image.getHeight(), OF_IMAGE_COLOR);  
  

so that there’s a pixel buffer to manipulate.