Blogger Scott

          在ImageView中顯示SD卡上的圖片

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

          例如在SD卡根目錄下有個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 江天部落格 閱讀(3948) 評論(0)  編輯  收藏 所屬分類: Android

          主站蜘蛛池模板: 双江| 涞源县| 咸丰县| 滨州市| 都兰县| 晋中市| 昭觉县| 建瓯市| 邯郸县| 偏关县| 长寿区| 池州市| 卓尼县| 建湖县| 来宾市| 霍城县| 晋城| 茶陵县| 保亭| 黑龙江省| 沙坪坝区| 朝阳市| 靖安县| 泊头市| 山阴县| 翼城县| 论坛| 邯郸市| 丰顺县| 绵竹市| 舞阳县| 正定县| 邯郸县| 郯城县| 北川| 吉林市| 平湖市| 黄梅县| SHOW| 环江| 齐齐哈尔市|