unsigned char* copyBMP(const char* filename, const char* hidden) { string h = hidden; ofstream geneModifier(hidden); int i; FILE* f = fopen(filename, "rb"); unsigned char info[54]; fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header for(i = 0; i < sizeof(info); i++) { geneModifier << info[i]; } // extract image height and width from header int width = *(int*)&info[18]; int height = *(int*)&info[22]; int size = 3 * width * height; unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once fclose(f); for(i = 0; i < size; i++) { geneModifier << data[i]; } geneModifier.close(); return data; }