java - 输出流仅保存 16 位的一半

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

最佳答案

writeShort(i) 写入一个简短的对吗?

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

实际上(short)0x00ffff00已经剪掉了。使用 int 例如

关于java - 输出流仅保存 16 位的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26254056/

相关文章:

java - 重命名未反射(reflect)在 JSON 输出中的类变量

arrays - Swift:无法将数组保存到 UserDefaults

nhibernate - NHibernate 可以在没有迭代器的情况下保存集合吗?

python - 如何将 Python tkinter canvas postscript 文件转换为 PIL 可读的图像文件?

c++ - 为什么当我调用 print() 函数时我的字符串不输出?

java - 使用 JPanel 引用更改子组件?

java - groovyc 不会报告多个错误

java - 是否可以发送输出流作为对 HTTP 请求的响应?

php - PHP 中用于增加页面加载时间的“输出缓冲”

java - J单元。并行运行。但是所有的测试方法都处理单例实例。怎么解决?