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 does like this:
The variable reduc are 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.
Result is like this:
(Tiny, isn't it? edit line 16 to 512x512 or something)
And the actual output is this:
Not sure, what is your exact requirement [ since you didnot paste a snippet of the code .. as Greg requested ], following example might resolve it :