62,616
社区成员
发帖
与我相关
我的任务
分享
public class Test01 {
public static void main(String[] args) {
int length = 0x1fa400;
int[] javaGraphic = new int[length]; // 怎么样转换成一个byte[].在线等???
byte[] bArray = new byte[length * 4];
for (int i = 0, j = 0; i < javaGraphic.length; ++i, j += 4) {
bArray[j + 0] = (byte) (javaGraphic[i] & 0xFF);
bArray[j + 1] = (byte) ((javaGraphic[i] >> 8) & 0xFF);
bArray[j + 2] = (byte) ((javaGraphic[i] >> 16) & 0xFF);
bArray[j + 3] = (byte) ((javaGraphic[i] >> 24) & 0xFF);
// 从byte转回int时, 只要做相应的左移就可以了, 右移24位的, 转回int时, 就左移24位
// 如: int temp = (bArray[j + 3] << 24) | (bArray[j + 2] << 16) | (bArray[j + 1] << 8) | bArray[j + 0]
}
}
}
public static byte[] intToByte(int[] ia)throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dis = new DataOutputStream(baos);
for(int e:ia)
{
dis.writeInt(e);
}
dis.flush();
dis.close();
return baos.toByteArray();
}