开发者

Merging two byteArray in android

I want to send the bitmap image through the bluetooth along with some other contents like char and int. The problem is to convert those things into single byte array. I tried by making it as two byte array and merging them but copyTo i开发者_Go百科s not working. Is there some other way to do it?


Use System.arraycopy method to copy one array into another

int lenA = arrayA.length;
int lenB = arrayB.length;
byte[] outArray = new byte[lenA + lenB];

System.arraycopy (arrayA, 0, outArray, 0, lenA);
System.arraycopy (arrayB, 0, outArray, lenA, lenB);

I haven't tested it, but should work.

edit:

And of course it's not recommended for big arrays. You're doubling data in memory in that way. I don't know what you're doing exactly with this data but if you can, use streaming instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜