Which method is more efficient for creating Bitmap out of Drawable from resources?
Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
Vs
Drawable myDrawable = getResources().getDrawable(R.drawable.icon_resource);
Bitmap myBitmap = ((BitmapDrawable) myDrawable).getBitmap();
since API 22 above method is deprecated so use following
Drawable myDrawable = ContextCompat.getDrawable(context, R.drawable.icon_resource)
You can take a look at the source code for Bitmap factory at http://source.android.com specifically the code for decodeResource.
I would reason that using BitmapFactory is preferred but in either case if you are decoding multiple bitmaps then you should call getResources() once and store the result for use as the resources argument for the functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With