Reading/Writing PPM image C++, new image is broken -


i found c++ code here on reading / writing images. improve can rotate etc. images. however, @ beginning have problems. when write image, seems read function read piece of it, since writes file piece of original image. please see code , input, output images.

    #include <iostream> #include <fstream> #include <string> using namespace std;  int main(int argc, char **argv) {     ifstream in;     in.open("oldimage.ppm", std::ios::binary);      ofstream out;      std::string magic_number;     int width, height, maxcolval, i, j;      in >> magic_number;     in >> width >> height >> maxcolval;     in.get();      char **image;     image = new char* [width];      for(i=0; i<width; i++)     {         image[i] = new char [height];          for(j=0; j<height; j++)         {             in >> image[i][j];         }     }      out.open("newimage.ppm", std::ios::binary);     out << "p3"     << "\n"         << width       << " "         << height      << "\n"         << maxcolval   << "\n"         ;      for(i=0; i<width; i++)     {         for(j=0; j<height; j++)         {             out << image[i][j];         }     }      in.clear();     in.close();      out.clear();     out.close();      return 0; } 

input image: https://www.dropbox.com/s/c0103eyhxzimk0j/oldimage.ppm?dl=0

output image: https://www.dropbox.com/s/429i114c05gb8au/newimage.ppm?dl=0

according this doc there 2 forms of ppm image file: raw , plain. seem assuming normal raw format using magic number p3 plain ppm. try p6.

also, height , width loops should other way round, doesnt affect result. presumably part of code rotate image.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -