开发者

Is it possible to create an array of Bitmap in android

开发者 https://www.devze.com 2023-03-13 15:48 出处:网络
I wanna create an bitmap array. Is it possible? If yes, which is the way to declare the Bitmap ar开发者_JAVA百科ray. and how to initialize it?

I wanna create an bitmap array. Is it possible? If yes, which is the way to declare the Bitmap ar开发者_JAVA百科ray. and how to initialize it?

Thank you


You could use an Arraylist :

ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
bitmapArray.add(myBitMap); // Add a bitmap
bitmapArray.get(0); // Get first bitmap

or simply an Array of bitmap like :

Bitmap[] bitmapArray = new Bitmap[];

Nevertheless be careful with the size of your image. You will probably have some trouble if you try to store lot of big image.


Yes it is possible, If bitmap1 and bitmap2 are objects of bitmap. I can assign them to an array as follows.

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};

Thanks Deepak


Just like any array, for example:

Bitmap[] bitmaps = new Bitmap[] { BitmapFactory.decodeResource(...) /* etc. */ }

There is nothing special in the fact that the objects in array are Bitmaps.


You can make bitmap aaray in android like this,

byte[] bMapArray= new byte[buf.available()];
            buf.read(bMapArray);
            Bitmap bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
            image.setImageBitmap(bMap);

Use this android developer documentation for details.

Use this too


All the above/below solutions are possible but a common case is actually using a HashMap as it is the case with Image Downloaders and async bitmap loaders.

A Bitmap is an object as may others (String arrays, Integer arrays etc...) so you might modify those methods you find also for storing bitmap arrays.

0

精彩评论

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