我正在处理图片。我想从标题中提取它的宽度和高度。解析文件头文件
宽度在位置
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