C# - 从已知偏移量

时间:2016-08-20 16:16:51

标签: c# windows visual-studio visual-studio-2013 windows-7

作为一个前言,这是我第一个适当的C#程序,我编程的经验主要是为TES5Edit制作Pascal脚本。在拉撒路做了两个实际的节目,但是,错了,他们非常可怕。

上传了当前代码' ere:http://www.mediafire.com/download/fadr8bc8d6fv7cf/WindowsFormsApplication1.7z

总之!我目前正在尝试做的是获取.dds文件中两个特定偏移量的字节值。 x分辨率保持@offset + 0c,由两个字节组成(所以+ 0c和+ 0d)。 y分辨率相同的演出; @ offset +10& +11。我在这里上传了我的发现:http://pastebin.com/isBKwaas

但是,我不知道如何做到这一点。我能够从各种谷歌搜索结果中解读的最多,结果就是:

        public void GetDDSDimensions(string strDDSFilename, out int iSourceDDSx, out int iSourceDDSy)
    {
        FileStream fsSourceDDS = new FileStream(strDDSFilename, FileMode.Open, FileAccess.Read);
        int iWidthOffset = 12; // 0c in hex, if byte is 00, then size is => 256, so get +0d as well
        int iHeightOffset = 16; // 10 in hex, same gig as above. Get byte @ +11 if +10 is 00.
        byte[] bufferDDSBytes = new byte[24]; // @ Offset +24 , byte is always 01. Use as a wee, err, "landmark".

    }

不知道如何继续前进。我需要以某种方式设置bufferDDSBytes来获取fsSourceDDS中的前24个字节,然后比较十六进制值@ + 0c和+10,以获得.dds文件的分辨率。

比较应该很容易; C#应该有一个与Pascal的StrToInt()函数相当的十六进制,不是吗?

1 个答案:

答案 0 :(得分:3)

首先,使用<div id="accordionexample"></div>: - )

using

要转到流中的特定偏移量,请使用using (FileStream fsSourceDDS = new FileStream(strDDSFilename, FileMode.Open, FileAccess.Read)) { // do something with the FileStream } // Ensures that it is properly closed/disposed 方法:

Seek

并在其上调用fsSourceDDS.Seek(someOffset, SeekOrigin.Begin); ReadByte方法以获取所需的字节数。读取字节后,流中的位置按读取的字节数提前。您可以使用Read属性获取流中的当前位置。要直接从流中读取小端值,可以使用Position类。

结合以上所有内容:

BinaryReader
相关问题