#include #include using namespace std; class Image_ByteArray_Image { public: static const int HELLO_IMAGE_2_MAX_PIC_SIZE = 10000000; char*& fileToBytesArray(const char * path, int & fileSize) const { char * buf = new char[HELLO_IMAGE_2_MAX_PIC_SIZE]; // initializing new buffer ifstream iFile = ifstream(path, ios::binary); // open file for reading // calculating file size iFile.seekg(0, ios::end); // jump to end of file fileSize = (int)iFile.tellg(); // tell end position iFile.seekg(ios::beg); // jump back to beginning iFile.read(buf, HELLO_IMAGE_2_MAX_PIC_SIZE); // read 10000000 Bytes of data from file iFile.close(); // close file return buf; } void saveBytesArrayToFile(char * & buf, int size, const char * path) const { FILE *stream = _fsopen(path, "wt", _SH_DENYWR); // open output file for writing(creating if not exists) fclose(stream); // close file if (stream != NULL) // if it was successful { ofstream oFile = ofstream(path, ios::binary); // open output file for writing for (size_t i = 0; i < (unsigned int)size; i++) // iterate buffer cells until its size oFile << buf[i]; // writing each cell(byte) to file oFile.close(); // close file } } };