Android: Displaying .jpg image from sdcard using ImageView

10,581

do NOT access the SD card directly, try accessing it trough Environment. Like this:

String imageDir = Environment.getExternalStorageDirectory()+"/apple.jpg";

and then you can call BitmapFactory:

Bitmap myBitmap = BitmapFactory.decodeFile(imageDir);
Share:
10,581
RagHaven
Author by

RagHaven

Generalist Software Engineer

Updated on June 04, 2022

Comments

  • RagHaven
    RagHaven almost 2 years

    I am trying to display a .jpg from my sd card into an imageview in my layout. I dont get any errors, but nothing gets displayed. I would appreciate any help. Thanks

    EDIT:

            layout1 = (LinearLayout) findViewById(R.id.layout1Activity);
    
         String imgFile = Environment.getExternalStorageDirectory() + "/Apple.jpg";
    
    
                Bitmap myBitmap = BitmapFactory.decodeFile(imgFile);
    
    
                ImageView myImage = new ImageView(this);
                myImage.setImageBitmap(myBitmap);
                layout1.addView(myImage);
    
  • RagHaven
    RagHaven almost 12 years
    Tried it. I still dont get the image. I edited my code to the updated version