android 根据SD卡中图片路径读取并显示SD中的图片――源代码

package com.guo;

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class MainAct extends Activity {
        /** Called when the activity is first created. */
        private ImageView img;
        //SD图片路径
        private String filepath = "/sdcard/hot.png";

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                img = (ImageView) findViewById(R.id.img);
                File file = new File(filepath);
                if (file.exists()) {
                        Bitmap bm = BitmapFactory.decodeFile(filepath);
                        //将图片显示到ImageView中
                        img.setImageBitmap(bm);
                }
        }
}


你可能感兴趣的:(android,图片,路径,显示)