java int[] 和 byte[] 互转,太tm坑了。。。

最近用camera360的sdk做滤镜。太tm有点小坑。。。主要就是byte[]和int[]互转。

int2Byte:

public static byte[] intArrToByteArray(int[] intArr) throws IOException {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(buf);
        for (int i : intArr) {
            out.writeInt(i);
        }
        byte[] b = buf.toByteArray();
        out.close();
        buf.close();
        return b;
    }

 

byte[] 2 int[]

ByteBuffer bb = ByteBuffer.wrap(arrRGBA);
int[] arrIntRGBA = new int[arrRGBA.length/4];
for (int i = 0; i < arrIntRGBA.length; i++) {
    arrIntRGBA[i] = bb.getInt();
}

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据