Search code examples
androidbitmapdrawableandroid-bitmap

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 ?


Solution

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

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