bool writeBinaryPGM(const string& filename, const vector<unsigned char>& image, int width, int height) {
ofstream file(filename, ios::binary);
if (!file.is_open()) {
cerr << "Error opening file: " << filename << endl;
return false;
}
file << "P5\n";
file << width << " " << height << "\n";
file << "255\n";
// Check if the file is open before writing the image data
if (file.is_open()) {
file.write(reinterpret_cast<const char*>(image.data()), width * height);
file.close();
return true;
} else {
cerr << "Error writing output PGM file." << endl;
return false;
}
}
#corrupted pgm file
8 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
oops
im trying to take a pgm file and apply a filter to it and output another pgm file with the filter in place
however after i run it, the new file wont open because it says that its corrupted idk why
these are my three functions and i have a main if they would be needed
bool readBinaryPGM(const string& filename, vector<unsigned char>& image, int& width, int& height);
bool writeBinaryPGM(const string& filename, const vector<unsigned char>& image, int width, int height);
void applyMedianFilter(const vector<unsigned char>& input, vector<unsigned char>& output, int width, int height);```
i just realized i posted in the wrong thread im sorry!