Skip to content

Instantly share code, notes, and snippets.

@topin89
Last active November 6, 2019 09:01
Show Gist options
  • Save topin89/aa1c378ac9f6a6b920195716f08bc1db to your computer and use it in GitHub Desktop.
Save topin89/aa1c378ac9f6a6b920195716f08bc1db to your computer and use it in GitHub Desktop.
Write PGM or PPM images (Portable Graymap and Portable Pixmap)
#include <fstream>
#include <iostream>
#include <string>
void writeppm(char const * const image_buffer,
int const image_size,
int const width,
int const height,
std::string const filename){
std::ofstream file{filename, std::ios::binary};
file << "P6\n" << width << '\n' << height << "\n255\n";
file.write(image_buffer, image_size);
}
void writepgm(char const * const image_buffer,
int const image_size,
int const width,
int const height,
std::string const filename){
std::ofstream file{filename, std::ios::binary};
file << "P5\n" << width << '\n' << height << "\n255\n";
file.write(image_buffer, image_size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment