0

I have an int array list which is used in an adapter to display images in gallery component.

int[] images = { R.drawable.hm1, R.drawable.hm2, R.drawable.hm3,
        R.drawable.hm4, R.drawable.hm5, R.drawable.hm6, R.drawable.hm7,
        R.drawable.hm8, R.drawable.hm9, R.drawable.hm10, R.drawable.hm11,
        R.drawable.hm12, R.drawable.hm13, R.drawable.hm14, R.drawable.hm15,
        R.drawable.hm16, R.drawable.hm17, R.drawable.hm18, R.drawable.hm19,
        R.drawable.hm20 };

Also i have a link to camera from my application, where we r saving the image to bitmap..i want to update the bitmap image to gallery component everytime i save it. Can u help me for this..?

Thanks in advance.

2
  • Fetch all the images taken from that "your" camera link that you have, and then call adapter.notifyDataSetChanged() method. Commented Oct 31, 2011 at 5:47
  • iam not knowing how to add bitmap image (saved from camera to my app) to the int array list, do i need to convert int array to bitmap array.. or can we get the int value of the bitmap to add it to the array?? Commented Oct 31, 2011 at 5:48

1 Answer 1

1

To Make Bitmap from the Resource

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.icon);

If you need can make array of the bitmap like this decoding each element.

When you take new image you can add that image to your array/list and update the adapter using notifyDataSetChanged.

Bitmap[] images = { BitmapFactory.decodeResource(getResources
(),R.drawable.hm1),BitmapFactory.decodeResource(getResources   
(),R.drawable.hm2),BitmapFactory.decodeResource(getResources(),R.drawable.hm3)}; 
Sign up to request clarification or add additional context in comments.

4 Comments

So, do i need to change every image's resource id (all) to bitmap and create a bitmap list..??
yeh, if you using your Resource then this is the way to make drawable image to Bitmap object.
Initially, i have 50-60 images.. Can we create a loop or method to convert all drawable images to bitmap object at once..??
you can make Bitmap array as you are creating int Array. just use the above method to create Bitmap instance..if gets OOM error then use createScaledBitmap() to minimize the size of bitmap BUT i will suggest you to do some RnD on Your App Requirement and find minimal and efficient way to do the thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.