c# - 将 32768kb EGA 文件转换为 256x256 Texture2D?

标签 c# c#-4.0 graphics xna

很抱歉,这是一个没有人帮助但原创海报的问题,但我正在尝试将 Ultima 4 的 SHAPES.EGA 转换为 Texture2D。 SHAPES.EGA中的每个字节代表2个像素点,共有256个16x16的图形。我需要将它们放在正方形中,因为 XNA 的 Reach 配置文件不支持高于 2048 的图像尺寸,无论实际图像大小如何。下面的代码让我得到了我想要的第一行,但是所有其他行都无法正常工作。 (假设它继续这种模式,第 17 行看起来就像第 2 行应该的样子。)我已经为此工作了几个小时,但目前我一无所获。

int cur_size = 16;

GFX.SHAPES_EGA = new Texture2D(GraphicsDevice, cur_size * 16, cur_size * 16);
Color[] temparray = new Color[(cur_size * 16) * (cur_size * 16)];

int CurrentIndex = 0, foo;
for (int Vertical = 0; Vertical < cur_size * 16; Vertical++) //16
{
    for (int Horizontal = 0; Horizontal < 16; Horizontal++)
    {
        for (int CurByte = 0; CurByte < 8; CurByte++)
        {
            //foo = (Vertical * (cur_size / 2)) + (Horizontal * 8 * cur_size) + CurByte;
            foo = (Vertical * (cur_size / 2)) + (Horizontal * 8 * cur_size) + CurByte;
            //Console.WriteLine((CurrentIndex * 2) + "+" + foo);
            temparray[(CurrentIndex*2)] = Basic.EgaToColor((File_SHAPES_EGA[foo] >> 4) & 0x0F);
            temparray[(CurrentIndex*2) + 1] = Basic.EgaToColor(File_SHAPES_EGA[foo] & 0x0F);
            CurrentIndex++;
        }
    }
}
GFX.SHAPES_EGA.SetData(temparray);

The image demonstrates that the image loading code is bugged.

最佳答案

尝试使用 Vertical += 16 而不是 Vertical++。为创世纪点赞!

关于c# - 将 32768kb EGA 文件转换为 256x256 Texture2D?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10713977/

相关文章:

c#-4.0 - Windows azure - 无法从传输连接读取数据: An existing connection was forcibly closed by the remote host

c# - 将 List<string> 转换为 byte[]

c - 寻找 C/C++ 中的 GD 教程

c# - 我应该如何缓冲绘制的矩形以提高性能(C#/.NET/WinForms/GDI+)

r - 绘制上三角矩阵或下三角矩阵的热图

简单程序的C#问题

c# - 根据列值显示/隐藏 jQuery 数据表操作链接按钮

c# - 尝试预测 .NET TcpClient.GetStream() 关于多线程环境中临时端口使用的行为

c# - 如何查看不同dll的执行时间

C# 访问另一个项目的 app.config 时出现问题