Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 根據SD卡中圖片路徑讀取並顯示SD中的圖片——源代碼

android 根據SD卡中圖片路徑讀取並顯示SD中的圖片——源代碼

編輯:關於Android編程

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

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved