I’m new to C++, and doing a bit of googling I thought sprintf would do the job, but I get an error upon compiling that I can’t convert between an unsigned char and a char. I need an unsigned char because I am going to print to an image file (0-255 RGB).
unsigned char*** pixels = new unsigned char**[SIZE];
vector<float> pixelColors;
...
sprintf(pixels[i][j][k], "%.4g", pixelColors.at(k));
(pixelColors has size of 3 and ‘k’ refers to a ‘for loop’ variable)
I’ll guess that the floats are in the range 0.0 … 1.0, then you do it like this:
The variable reduc is now 128.
EDIT: complete example, outputting image in Net PPM format.
}
I hope this helps you. You can read about Netpbm format on wikipedia.
EDIT2: The image output is clear text.
(Tiny, isn’t it? edit line 16 to 512×512 or something)
Result is like this:
And the actual output is this: