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

时间:2012-05-23 05:30:02

标签: 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.

1 个答案:

答案 0 :(得分:1)

而不是Vertical++尝试Vertical += 16。为Ultima竖起大拇指!