11

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

0

6 Answers 6

4

Eclipse Project -> Clean helped in my case.

Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

3

Please make sure that all the sdk componenets (E.G Eclipse, Android SDK, SDK plug in for eclipse are all up to date).

Comments

1

I got null when i used a jpeg image file. But when i converted it to png and then used it in the same place it worked correctly

Comments

0

my problem was that i was using R.drawable.clickCamera, but clickCamera was actually an XML drawable (for a button with selectable states), not an actual image. that was silly.

Comments

-1

Check options parameter when calling BitmapFactory.decodeResource. It is third parameter of this method and have to be set to false for returning a bitmap.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.