1

I would like to convert my ppm image to a jpeg with libjpeg. But how can I do that, or is it simpler to write a jpeg with my data instead of converting the ppm? Here is my code for writing the ppm file:

void PPMOutput::createOutput( string fileName, string content, string maxValueColor, int width, int height ){
    string fName = fileName + ".ppm";
    const char * fNameConst = fName.c_str();
    ofstream myfile;
    myfile.exceptions ( std::ofstream::failbit | std::ofstream::badbit );
    try{
        myfile.open(fNameConst);
        myfile << "P3 \n \
            # sample.ppm \n" << \
            height << " " << width << " \n " << \
            255 << "\n";
        myfile << content;
    }catch( exception const &e ){
        cerr << "Exception writing PPM file!" << endl;
    }
    myfile.close();
    cout << "Saved results to \"" << fileName << ".ppm\"." << endl;
}

SO can I somehow pass the content string used for the ppm to jpeg to create an image out of it? I even do not know if I a doing the ppm function right because I can only open the ppm file with gimp to see something. I would be very thankful for help!

Best regards!

potu1304
  • 75
  • 4
  • 19

0 Answers0