Blogger Scott

          在ImageView中顯示SD卡上的圖片

          Android應(yīng)用中顯示SD卡上的圖片可以使用ImageView,并用BitmapFactory的decodeFile讀取文件。

          例如在SD卡根目錄下有個(gè)JPG文件DSC0001.jpg。main.xml文件如下:

          <?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">

          <ImageView
                  
          android:id="@+id/jpgview"
                  android:layout_width
          ="fill_parent"
                  android:layout_height
          ="fill_parent"
          /> 

          </LinearLayout>


           

          JAVA代碼如下:

                     public void onCreate(Bundle savedInstanceState) {
                             
          super.onCreate(savedInstanceState);
                             setContentView(R.layout.main);
                             ImageView jpgView 
          = (ImageView)findViewById(R.id.jpgview);
                             String myJpgPath 
          = "/sdcard/DSC_0001.JPG"
                             BitmapFactory.Options options 
          = new BitmapFactory.Options();
                             options.inSampleSize 
          = 2;
                             Bitmap bm 
          = BitmapFactory.decodeFile(myJpgPath, options);
                             jpgView.setImageBitmap(bm);




           

          posted on 2010-02-19 15:01 江天部落格 閱讀(3938) 評(píng)論(0)  編輯  收藏 所屬分類: Android

          主站蜘蛛池模板: 杭锦旗| 邢台县| 宁武县| 都兰县| 奈曼旗| 海宁市| 常熟市| 阿尔山市| 达孜县| 视频| 綦江县| 临潭县| 渭南市| 彰化县| 古浪县| 三原县| 基隆市| 河北区| 乌苏市| 平乡县| 镶黄旗| 界首市| 泊头市| 聂拉木县| 北京市| 曲靖市| 峡江县| 澜沧| 西林县| 红桥区| 五指山市| 珠海市| 平陆县| 昭苏县| 鹰潭市| 平果县| 南华县| 阿坝| 微博| 房产| 定边县|