Writing PPM image file in C++
Following is the C++ code for writting the ppm image file
strtemp has file name,
fData is the pointer to the image data.
sprintf(strtemp,”%04d.ppm”,imageNo);
ofstream output(strtemp, ios::binary|ios::out);
if(!output){
cout << ” unable to open the output file “<< strtemp << endl;
}
else{
output << “P6″<< endl <<”# foreground “<<endl;
output << itoa(IWidth, strtemp, 10);
output << ” “;
output << itoa(IHeight, strtemp, 10);
output << endl;
output << itoa(255, strtemp, 10) << endl;
output.write( (char *)fData, IHeight*IWidth*3);
output.close();};//end of else