Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create drawable from bitmap

ALL,

As suggested here I need to make a drawable out of my bitmap. But when I tried to use:

 Drawable d = new Drawable( my_bmp);

it shows that this constructor is deprecated in favour of:

 Drawable(Bitmap bmp, int resourceId)

How else I can make a drawable out of bitmap?

Thank you.

like image 427
Igor Avatar asked Apr 15 '14 04:04

Igor


1 Answers

You can use

Drawable d = new BitmapDrawable(getResources(), my_bmp);

A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object.

BitmapDrawable(Resources res, Bitmap bitmap)

Create drawable from a bitmap, setting initial target density based on the display metrics of the resources.

Also look a the public constructors @

http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html

like image 110
Raghunandan Avatar answered Oct 14 '22 19:10

Raghunandan