How to convert int[] to byte[]

前端 未结 6 514
花落未央
花落未央 2020-11-27 04:39

I have an array of integers which represent a RGB image and would like to convert it to a byte array and save it to a file.

What\'s the best way to convert an array

6条回答
  •  一整个雨季
    2020-11-27 05:06

    You need to decide how you convert 1 integer to a set of bytes first.

    Most probably (?) 1 integer to 4 bytes, and use the shift (>> or <<) operators to get each byte out (watch that byte ordering!). Copy to a byte array 4 times the length of the integer array.

提交回复
热议问题