This is a project I've been struggling with and now it works. I'm publishing the TestImageLoad.java and main.xml
The file on the sd card is named in a constant, which is ok for my app. There are some options for the bm = BitmapFactory.decodeStream(is, null, null); function but I am ignoring them.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test Image Load"
/>
<ImageView android:id="@+id/picview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The TextView is non functional.
TestImageLoad.java
package com.example.testimageload;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.ImageView;
public class TestImageLoad extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File f = new File(Environment.getExternalStorageDirectory()+"/photo.jpg"); // or "/sdcard/photo.jpg"
FileInputStream is = null;
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
Log.d("John: ", "file Not Found");
}
Bitmap bm;
bm = BitmapFactory.decodeStream(is, null, null);
ImageView pic=(ImageView)this.findViewById(R.id.picview);
pic.setImageBitmap(bm);
}
}


