C++ 中的文件读取
我正在通过c++进行图像处理,我必须读取char格式的jpeg图像的标题,我必须检查图像的相机/系统/设备信息,我该怎么做。
I am working on the image processing through c++, I has to read the header of jpeg image in char format, I has to check the camera/system/device information of image, how can i do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果文件不太大,您可以将其全部读入内存:
您的文件将存储在向量
buf
中。如果您只想读取标头,则可以读取较小的块,而不是整个filesize
,并适当地处理它们。If the file isn't too big, you can read it all into memory:
Your file will be stored in the vector
buf
. If you only want to read the header, you can read smaller chunks, rather than all offilesize
, and process them appropriately.一般来说,图像的“元”部分是固定大小的。
使用 istream::read 和二进制模式将文件读取为向量。使用图像格式规范,找到您需要的字段。
一次构建一个字节的多字节整数,而不是尝试将一个位置转换为整数并读取。这将帮助您克服字节顺序问题。
In general, the "meta" section of images are a fixed size.
Read the file, using
istream::read
and binary mode into a vector. Using the image format specification, locate the field you need.Build multibyte integers one byte a time, rather than trying to cast a location as an integer and reading. This will help you overcome the issue of Endianness.