我正在處理圖片。我想從標題中提取它的寬度和高度。解析文件頭文件
寬度在位置
size
4B width
4B height
它們在特定指數表示來表示。
我試圖解析它並與代碼
ifstream f(name, ios::binary | ios:: in); // reading a file in binary
ostringstream ob;
if (f.fail()){ // fail test
return false;
}
f.seekg (0, f.end);
int length = f.tellg(); // length of the file
memory = new char[length]; // allocate array of chars
f.read (memory, length); // read the content of the file into an array
f.seekg (0, f.beg); // point back at the beginning of the file.
他們每個人都有4B提取它,因此,使用用於循環
for (int i = index ; i <4 ;i++){
cout << hex<< memory[i];
}
或我什它使用它轉換成數
string a;
for (int i = index; i < 4 ;i++{
a+=memory[i];
}
cout << atoi(a.c_str()) << endl;
應輸出一個數字,但它輸出一些不可讀的格式。
什麼是'索引'?你是指'for(int i = index; i
MikeCAT
切勿使用'new type [count]',而應使用'vector'。無論如何,你將不得不爲你的問題提取一個最小的例子來符合網站規則。 ATM它是無關緊要的。 –
你有鏈接到標題的格式嗎?它的前兩個值是高度和寬度嗎?文檔是否告訴你什麼「endian」用於存儲數字? – Galik