0
我 後讀入串矢量一個bmp圖像和存儲轉換的char數和二進制數:寫二進制數爲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;
}
這是好了,但我想重寫bmp文件,將每個二進制數字轉換爲char,並將其存儲在新文件中。
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?