【发布时间】:2016-12-27 15:09:30
【问题描述】:
作为一个小小的前注,这是我第一个正确的 C# 程序,我的编程经验主要是为 TES5Edit 制作 Pascal 脚本。在 Lazarus 中制作了两个实际的程序,但是,呃,它们非常糟糕。
上传了我当前的代码'ere:http://www.mediafire.com/download/fadr8bc8d6fv7cf/WindowsFormsApplication1.7z
无论如何!我目前正在尝试做的是获取 .dds 文件中两个特定偏移量的字节值。 x 分辨率保持@offset +0c,由两个字节组成(即+0c 和+0d)。 y 分辨率的相同演出; @ 偏移 +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() 函数的十六进制,不是吗?
【问题讨论】:
-
所以基本上你是在问如何从特定的文件偏移量读取 Little-endian 编码的
ushort。 -
对,呃,LE和BE是跟字节顺序有关的;所以在 LE 中,十六进制值 4000 写为 '00 40',但在 BE 中,它写为 '40 00',是吗?而 ushort 似乎只是一个小的整数变量。
-
正确。实际看数据,很可能是 LE
ints (4 bytes) at offset 0xc, 0xc+4
标签: c# windows visual-studio visual-studio-2013 windows-7