当前位置:操作系统 > 安卓/Android >>

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); 
                } 
        } 

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 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,