[英]How to convert an ArrayList of byte[] to an array of Integer in Android?
I'm trying to convert an ArrayList<byte[]> listByte
to an Integer[] arrInteger
. 我正在尝试将ArrayList<byte[]> listByte
转换为Integer[] arrInteger
。 I'm getting the listByte
of pictues from a server through an object. 我正在通过对象从服务器获取listByte
的listByte。 My goal is to get this Array of Integer
(pictures) to later use it in a ListView
( arrayAdapter = new MyClass(MyActivity.this, stringArr, arrInteger);
. I tried like this: 我的目标是获取此Array of Integer
(图片),以便以后在ListView
使用它( arrayAdapter = new MyClass(MyActivity.this, stringArr, arrInteger);
ArrayList<Integer> integerList = new ArrayList<>();
for (int i = 0; i < objectList.size(); i++) {
integerList.add(ByteBuffer.wrap(objectList.get(i).getPicture()).getInt(i));
/*integerList.add(new BigInteger(objectList.get(i).getImage()).intValue());*/ //I tried this too
}
and to an Array of Integer
, like this: 和一个Array of Integer
,如下所示:
Integer[] arrInteger = new Integer[integerList.size()];
arrInteger = integerList.toArray(arrInteger);
When i run the app, the ListView
is showing without pictures. 当我运行该应用程序时, ListView
显示为无图片。 So I used debug and I found that my arrInteger = null
!. 所以我使用了调试,发现我的arrInteger = null
!。 How do I convert correctly? 如何正确转换?
Decode back to Bitmap 解码回位图
ArrayList<Bitmap> imgs = new ArrayList<Bitmap>();
for(byte[] array: listByte)
{
Bitmap bm = BitmapFactory.decodeByteArray(array, 0, array.length); //use android built-in functions
imgs.add(bm);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.