Convert drawable by id To Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Convert

Description

Convert drawable by id To Bitmap

Demo Code

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Main {

  public static Bitmap drawableTobitmap(Context mContext, int drawable) {

    Drawable myDrawable = mContext.getResources().getDrawable(drawable);
    return ((BitmapDrawable) myDrawable).getBitmap();
  }/* ww w.jav a 2  s . c o m*/

}

Related Tutorials