输出流只保存16位的一半

时间:2014-10-08 09:54:26

标签: java save outputstream 16-bit

这就是我所拥有的:

 Main:
 buff.clearColor((short)0x00ffff00);

 - - - - - -

 Buffer:
 DataOutputStream dataOutputStream = new DataOutputStream(out);
 for (int i : colorBuffer) {
 dataOutputStream.writeShort(i);
 }

void clearColor(short c)
{
    for(int i=0; i<width*height; i++)
    {
        colorBuffer [i] = c;
    }
}

并且在文件中只保存了0x00ffff00的一半, 这一个:ff00

... ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ff00 ...

1 个答案:

答案 0 :(得分:1)

writeShort(i)写一个简短的吧?

short只有 2个字节.... 你需要4个,不是吗?

实际上(short)0x00ffff00已经削减了它。使用int例如