0

Possible Duplicate:
How to convert a Drawable to a Bitmap?

I have just started learning android, so im a newbie

I am trying to create an android application for image processing for my Project

I came accross the blog entry :

http://xjaphx.wordpress.com/2011/06/22/image-processing-brightness-over-image/

I am facing the following problem;

I am unable to create a Bitmap object for my image stored as /res/drawable/pic_1.jpg

I have tried using

Bitmap myBitmap = BitmapFactory.decodeFile("/res/drawable/pic_1.jpg"); and called the function;

public static Bitmap doBrightness(myBitmap, int value) {.........}

but that didnt work;

then I tried,

Bitmap myBitmap = BitmapFactory.decodeFile("/res/drawable/pic_2.jpg");
imageview.setImageBitmap(myBitmap);

without calling the doBrightness() function.yet,it displays nothing in the imageview.

so I guess BitmapFactory.decodeFile() is returning null.

so what i wanted to know is, how is it possible to create Bitmap object for an image stored in /res/drawable?

Community
  • 1
  • 1
user1713886
  • 11
  • 1
  • 1

2 Answers2

4

you should get the Image via the resources, not by path:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
stealthjong
  • 10,858
  • 13
  • 45
  • 84
3

Use this

Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(),
                                R.drawable.icon);
Chinmoy Debnath
  • 2,814
  • 16
  • 20