Mouna
Mouna

Reputation: 627

Create Bitmap from drawable

I would like to add an image (Bitmap) over another one. For that I am only using Bitmaps (fot the image I draw in and the image I add), but the Bitmap I am using is actually a resource in my drawable resource. So Is there a way to create a Bitmap that contains my drawable ?

Upvotes: 0

Views: 2119

Answers (2)

jyomin
jyomin

Reputation: 1967

Try this:

Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(), 
    R.drawable.icon_name);

Upvotes: 1

Hamid Shatu
Hamid Shatu

Reputation: 9700

Use decodeResource() of BitmapFactory to convert drawable resource into Bitmap as follows...

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.your_drawable);

Upvotes: 2

Related Questions