反序列化特定的二进制文件使用c#属性deserializing specific property of binary file using c#

- 此内容更新于:2015-01-06
主题:

原文:

I've got the following problem, I have a custom filetype and I want it to display a specific image that's serialized in it (this file is serialized in binary) but my files sizes can reach up to Gb of size.

So to avoid performance issues due to possible huge file sizes I would like to deserialize the property of the image without having to deserialize all the unnecessary information that the file contains.

Is that even possible?

Sinatr的回复:这# 39;年代完全取决于文件格式。二进制不是一个格式,但在某些术语,意思是什么文件格式而不是文本。通常不同的文件格式有头、数据属性,等等。它只可能通过阅读标题定位,然后你需要只读属性,如果你知道它的位置(位置)文件。

(原文:It's totally depends on file format. Binary is not a format, but a term meaning what file is in some format which is not a text. Typically different file formats have header, data, properties, etc. It may be possible by reading only header locate and then read only property you need, if you know its location (position) within file.)

user2144236的回复:由于@Sinatr这# 39;只是我所需要的东西但是我# 39;已经意识到房地产,我想反序列化不是以一个恒定的位置,我也不有必要的信息在数学上找到它。我# 39;不得不打开该文件的程序生成的文件和随后得到我需要的信息。

(原文:Thanks @Sinatr that's just about what I need but I've realized that the property that I want to deserialize is not at a constant location, neither do I have the necessary information to mathematically find it. I'll have to open the file with the program that generated the file and subsequently get the piece of information that i need.)

Sinatr的回复:文件格式设计的吗?然后您可以简单地使用现有的序列化器来序列化器/反序列化头/属性/数据。看看protobuf.net。文件格式可以是:格式标签,标题大小头、数据。那么你刚才读的格式标记,确保变# 39;你的格式,那么大小,然后头,标题,标题属性进行反序列化。

(原文:Is file format designed by you? Then you can simply use existing serializers to serializer/deserialize header/properties/data. Check out protobuf.net. File format can be: format tag, header size, header, data. Then you just read format tag to ensure it's your format, then size, then header, then deserialize header and get header properties.)

Marc Gravell♦的回复:你使用序列化?它是什么格式的?

(原文:What did you use to serialize? What format is it in?)

解决方案:
我不确定正确的理解你的问题,但是你应该手动解码文件文件流,只提取文件包含图像的块
原文:

I'm not sure to have understood your question properly, but you should decode your file manually with a FileStream and extract just the chunk of file containing the Image