Reputation: 13
I have this code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView = (ImageView) findViewById(R.id.image);
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
mImageView.setImageBitmap(mBitmap);
}
It works fine in Android Emulator Level 6 but not work in Emulator level 5, not depend on level of library was added in my project. In Emulator level 5, BitmapFactory.decodeResource return null.
How to fix it. Plz help me.
Upvotes: 1
Views: 1549
Reputation: 1
I recommend you call BitmapFactory.decodeResource
with three parameters. create third parameter with this code:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =false;
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
Upvotes: 0
Reputation: 67296
Try this,
Create a drawable
folder inside res
folder and keep your icon.png
image.
res/drawable/icon.png
And then you can try the above code.
Upvotes: 1