1

I am trying to use this:

BitmapFactory.decodeFile("logo.jpg")

and I don't seem to have the file: logo.jpg in the right place in comparison to my apk. where should it go?

P.S. the error I get is:enter image description here

Edit

I now am using this: >BitmapFactory.decodeResource(getActivity().getResources(),"logo.jpg")

and am now getting a compiler error that says:

The method getActivity() is undefined for the type Brick (Brick is the name of the class)

I don't care which solution works as long as one of them does

jth41
  • 3,808
  • 9
  • 59
  • 109
  • Currently where is your logo file? – Paresh Mayani Apr 11 '13 at 02:43
  • well in an attempt to get lucky Ive put a copy several places ;). In bin and bin\res and bin\res\drawable-hdpi and bin\res\drawable-mdpi and and bin\res\drawable-xhdpi and and bin\res\drawable-xxhdpi – jth41 Apr 11 '13 at 02:49

2 Answers2

1

Where would you like to put your "logo.jpg" file?

  1. If you would like to put it in the drawable folder, then use:

    BitmapFactory.decodeResource(getResources(), R.drawable.logo);
    
  2. If you would like to put it somewhere on your device's memory, then use:

    BitmapFactory.decodeResource("/sdcard/logo.jpg");
    

And here's some guide to help you start: http://developer.android.com/reference/android/graphics/BitmapFactory.html

Hanny Udayana
  • 388
  • 3
  • 21
1

I think what you are trying to do is to put an JPG file into your project and load via Java code, is that correct.

If so, you'll need to put your logo.jpg into your assets folder,

and load it using the similar method as this SO answer stated:

https://stackoverflow.com/a/8502231/763459


For your convenience I pasted the code as below:

InputStream bitmap=null;

try {
    bitmap=getAssets().open("logo.png");
    Bitmap bit=BitmapFactory.decodeStream(bitmap);
    img.setImageBitmap(bit);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if(bitmap!=null)
    bitmap.close();
}
Community
  • 1
  • 1
dumbfingers
  • 7,001
  • 5
  • 54
  • 80