是否可以在android中创建位图数组
我想创建一个位图数组。可能吗? 如果是,则使用哪种方式声明位图数组。如何初始化它是否可以在android中创建位图数组,android,Android,我想创建一个位图数组。可能吗? 如果是,则使用哪种方式声明位图数组。如何初始化它 谢谢就像任何数组一样,例如: Bitmap[] bitmaps = new Bitmap[] { BitmapFactory.decodeResource(...) /* etc. */ } 数组中的对象是位图s这一事实没有什么特别之处。您可以使用Arraylist: ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>(); bitm
谢谢就像任何数组一样,例如:
Bitmap[] bitmaps = new Bitmap[] { BitmapFactory.decodeResource(...) /* etc. */ }
数组中的对象是
位图
s这一事实没有什么特别之处。您可以使用Arraylist:
ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
bitmapArray.add(myBitMap); // Add a bitmap
bitmapArray.get(0); // Get first bitmap
不过,要注意图像的大小。如果你试图存储大量的大图像,你可能会遇到一些麻烦。你可以在android中这样制作位图Aray
byte[] bMapArray= new byte[buf.available()];
buf.read(bMapArray);
Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
image.setImageBitmap(bMap);
请使用此android开发者了解详细信息
使用太多是的,这是可能的,
如果位图1和位图2是位图的对象。我可以按如下方式将它们分配到数组
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(),R.drawable.a_thumb);//assign your bitmap;
Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(),R.drawable.anotherimage);//assign your bitmap;
Bitmap[] arrayOfBitmap = {bitmap1, bitmap2};
谢谢
Deepak以上/以下所有解决方案都是可能的,但一个常见的情况是使用HashMap,因为它与图像下载程序和异步位图加载程序一样
位图和其他对象(字符串数组、整数数组等)一样都是对象,因此您可以修改存储位图数组的方法。请小心,因为如果加载的位图太大/太多,可能会很快导致内存不足问题。
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(),R.drawable.a_thumb);//assign your bitmap;
Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(),R.drawable.anotherimage);//assign your bitmap;
Bitmap[] arrayOfBitmap = {bitmap1, bitmap2};