开发者

BitmapFactory.decodeResource return null in Emulator API level 5

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.


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜