如何从文件数据中读取字节(传递头) [英] How to read bytes from data of file (passing header)

查看:183
本文介绍了如何从文件数据中读取字节(传递头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要传递标题部分并获取文件的仅字节内容。例如,我想从bmp文件或jpg文件中只读取RGB字节;或者我想从txt文件中只读文本内容。我如何获得内容字节。



File.ReadAllBytes(C:\\\\ .jpg)



此方法使用标题读取。我不想要标题部分。



谢谢



我尝试过:



Marsal方法。但是很难。

I want pass header section and get bytes only content of a file. For example i want read only RGB bytes from a bmp file, or jpg file; or i want read only text content from a txt file. How can i get content bytes.

File.ReadAllBytes("C:\\a.jpg")

This method reading with headers. I don't want headers section.

Thanks

What I have tried:

Marsal method. But it was difficult.

推荐答案

你无法直接从JPG文件读取RGB格式 - 它使用有损压缩技术,这意味着每个像素值都在图像不是由JPG文件中的值直接表示的。



如上所述,所有文件格式都不同,因此任何标题都是不同的长度或不存在。例如,文本文件根本没有标题,而位图可以有多个标题,如果您还考虑颜色表等等 - 无论如何都不是固定长度。
You can't read the RGB format directly from a JPG file - it uses a lossy compression technique which means that every pixel value in the image isn't directly represented by a value in the JPG file.

And as stated, all file formats are different, and so any "header" will be a different length or non-existent. For example, a text file would not have a header at all, while a bitmap could have multiple headers if you also consider colour tables and so forth - which are not of a fixed length anyway.


只是添加到已经说过的内容,文件格式中文件中的每个记录都有一个标题。



您对所需内容的描述是非常天真地看待应用程序和文件是如何工作的。



并非所有文件都有标题,也没有任何标题信息具有相同的格式,也没有相同的长度,也没有相同的目的。



你实际上必须确切地知道文件是如何布局的,哪些字节意味着使用这些文件的应用程序是什么,这些字段是什么字节偏移在文件中,它们是什么类型,字段和块长度,...



您甚至可以遇到一个字段指定另一个字段的偏移量或阻止文件,因为某些字段或块d在文件中没有特定的偏移量。
Just to add to what's already been said, there are file formats where each "record" in the file has a header.

Your description of what you want is a very naive view of how applications and files work.

Not all files have a header, nor is any header information the same format, nor the same length, nor has the same purposes.

You actually have to know exactly how the file is laid out, which bytes mean what to the application that uses those files, what byte offset these fields are at in the file, what type they are, field and block lengths, ...

You can even run into situations where one field specifies an offset for another field or block in the file because some fields or blocks don't have specific offsets in the file.


这篇关于如何从文件数据中读取字节(传递头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆