Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 21-Jun-18 4:35am
Comments
F-ES Sitecore 21-Jun-18 9:21am    
Every file format is different, you'll simply need to know how many bytes are in the header of each file format you support and skip past them.
gacar 21-Jun-18 9:32am    
If so very bad. Do you know, how can i get list of file structures. Is there a list?
Eric Lynch 21-Jun-18 9:39am    
In the case of ".jpg" files: https://en.wikipedia.org/wiki/JPEG
F-ES Sitecore 21-Jun-18 9:39am    
You can find the structures of popular formats by googling for them.
Richard MacCutchan 21-Jun-18 10:19am    
In addition to the other comments, even if you skip the headers you still need to understand the structure of the remaining bytes.

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.
 
Share this answer
 
Comments
gacar 21-Jun-18 10:51am    
Thanks for your comment.
OriginalGriff 21-Jun-18 11:17am    
You're welcome!
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.
 
Share this answer
 
Comments
gacar 21-Jun-18 10:51am    
Thanks for your comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900