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?