Monday, February 13, 2012

How to Convert Drawable to Bitmap and Vice versa in android?


Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.setBounds(0, 0, w, h);
d.draw(canvas);

and Convert Bitmap to Drawable


BitmapDrawable bitmapDrawable = (BitmapDrawable)bitmap;
Drawable drawable = (Drawable)bitmapDrawable;
Bitmap bitmap = new Bitmap (...);
Drawable drawable = new BitmapDrawable(bitmap);


No comments:

Post a Comment