6

i can't find setImageBitmap from ImageSwitcher. is there a way to set it by a bitmap?

UPDATES1 then i found this -> set Image from file URI

But my case is, i have to draw something in the bitmap before it set to ImageSwitcher. So, is there no way to set it via bitmap? if no way, i have to output the image file from modified bitmap then use setImageURI. But this is wasting of memory.

UPDATES2 Alternative: Is there a way to dynamically store the image file from sdcard to R.drawable or R.raw to generate resource/drawable id. Then use it to setImageResource or setImageDrawable?

Community
  • 1
  • 1
eros
  • 4,946
  • 18
  • 53
  • 78

2 Answers2

13

you can convert bitmap into drawable and assign drawable to image switcher as

Drawable drawable =new BitmapDrawable(bitmap);
mSwitcher.setImageDrawable(drawable);
deepa
  • 2,496
  • 1
  • 26
  • 43
11

You can wrap your Bitmap in BitmapDrawable and use ImageSwitcher.setImageDrawable.

Darth Beleg
  • 2,657
  • 24
  • 26
  • now i can set the bitmap via bitmapdrawble. but the imageswitcher's view size change to bitmap size. before it was on fullscreen. – eros Sep 15 '11 at 04:47
  • 1
    Are you using wrap_content for the ImageSwitcher and ImageViews in it? Could you post your layout and what are you expecting to see? – Darth Beleg Sep 16 '11 at 02:39
  • would you suggest me the efficient way to set ImageSwitcher image using BitmapDrawable (the bitmap must be mutable)? I am receiving out of memory error – eros Sep 21 '11 at 03:40
  • BitmapDrawable should not add much overhead compared to a simple Bitmap. So I can only suggest you to explicitly recycle your bitmaps when you no longer need them. I developed a slideshow apllication recently and used out animation's callback to recycle a bitmap when it goes away. – Darth Beleg Sep 22 '11 at 08:05