Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitmapFactory.decodeResource returns null value

Tags:

android

I am tring to load bitmaps from an internal resource in a View object (the source itself is in "drawable" files).

the code is:

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;


public class BannerView extends View {



 private Bitmap m_Banner = null;

 public BannerView(Context context, AttributeSet attributeSet) {
  super(context, attributeSet);

  m_Banner = BitmapFactory.decodeResource(getResources(), R.drawable.banner);

 }
}

Why m_Banner value is null?

thank you in advance

Kobi

like image 523
krasnoff Avatar asked Dec 09 '10 22:12

krasnoff


2 Answers

Eclipse Project -> Clean helped in my case.

like image 120
altumano Avatar answered Nov 02 '22 10:11

altumano


I have the same problem too, but I've found that if I put the picture into drawable-ldpi, it works fine. I do not know why, but this worked for me.

like image 44
Yang Li Avatar answered Nov 02 '22 08:11

Yang Li