Home > C++, File-Handling, ImageProcessing > Writing PPM image file in C++

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

Advertisements
Categories: C++, File-Handling, ImageProcessing Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: