Beginner Beginner -5 years ago 220
Android Question

How to set a bitmap from resource

This seems simple, i am trying to set a bitmap image but from the resources i have within the application in the drawable folder.

bm = BitmapFactory.decodeResource(null,;

Is this correct ?

Answer Source

Assuming you are calling this in an Activity class

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);

The first parameter, Resources, is required. It is normally obtainable in any Context (and subclasses like Activity).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download