How can I convert a Bitmap image to Drawable ?
467
votes
Hi i got the answer of your question follow this link and got the right answer i do it. and i success,i hope you got the success. best of luck androidsnippets.com/convert-bitmap-to-drawable
- Zala Janaksinh
Contribution is a great way to say thanx... :) Contributions in terms of giving answers... :)
- Farhan
@Farhan k ...... .
- Abhi
11 Answers
274
votes
Sounds like you want to use BitmapDrawable
From the documentation:
A
Drawablethat wraps a bitmap and can be tiled, stretched, or aligned. You can create aBitmapDrawablefrom a file path, an input stream, through XML inflation, or from aBitmapobject.
852
votes
153
votes
Having seen a large amount of issues with bitmaps incorrectly scaling when converted to a BitmapDrawable, the general way to convert should be:
Drawable d = new BitmapDrawable(getResources(), bitmap);
Without the Resources reference, the bitmap may not render properly, even when scaled correctly. There are numerous questions on here which would be solved simply by using this method rather than a straight call with only the bitmap argument.
35
votes
Offical Bitmapdrawable documentation
This is sample on how to convert bitmap to drawable
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
32
votes
20
votes
11
votes
10
votes
1
votes
0
votes