charを数値と2進数に変換した後、bmp画像を読み取り、文字列ベクトルに格納します。
typedef unsigned char BYTE;
std::streampos fileSize;
std::vector<BYTE> readFile(const char* filename)
{
// open the file:
std::ifstream file(filename, std::ios::binary);
// get its size:
file.seekg(0, std::ios::end);
fileSize = file.tellg();
file.seekg(0, std::ios::beg);
// read the data:
std::vector<BYTE> fileData(fileSize);
file.read((char*) &fileData[0], fileSize);
return fileData;
}
これは今のところ良いことですが、各2進数をcharに変換した後、bmpファイルを書き直して、新しいファイルに保存したいと思います。
ofstream saveFile(path);
int i=0; string str="";
while(i<binary.size()) //the binary_size is a string that contain all binary number of bmp
{
str=BinartToInt(binary[i]);//BinartToInt is a function that convert 8bit binary to number
saveFile <<str;
i++;
}
saveFile.close();
ベクトルバイナリ文字列をBMPに変換するにはどうすればよいですか?