android 从 SD 卡读取图像

标签 android sd-card

我正在尝试从我的 SD 卡中读取图像,但我不确定我的操作是否正确。需要一些帮助

这是我阅读它的代码:

String imageInSD = "/sdcard/Hanud/" + c.getString(1) + ".PNG";
        Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
        ImageView myImageView = (ImageView)findViewById(R.id.imageview);
        myImageView.setImageBitmap(bitmap);

这是我的主文件:

<?xml version="1.0" encoding="utf-8"?>
<WebView 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/webview"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

 <!-- <ImageView
    android:id="@+id/image"
    android:scaleType="center"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    />-->

    <ImageView
  android:id="@+id/imageview"
  android:layout_gravity="center"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:scaleType="center"
  />


  <TextView  
    android:id="@+id/myNameText"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
  />
</WebView>

最佳答案

应该是:

String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() +"/Hanud/" + c.getString(1) + ".PNG";
        Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
        ImageView myImageView = (ImageView)findViewById(R.id.imageview);
        myImageView.setImageBitmap(bitmap);

这将确保您找到正确的目录!

关于android 从 SD 卡读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5613123/

相关文章:

android - PhoneGap/Cordova Android 在 onDeviceReady 后获取屏幕尺寸

安卓保存图片到sd卡报错

android - 各种android应用主屏设计模式

android - 使用方向键在同一 fragment 中的 LinearLayouts 之间移动焦点/导航

linux - SD 卡中的精简配置

java - 如何在android中获取存储在sd卡中的文件名

java - 在SD卡中添加多张图片

android - 使用 JSON 向 GCM 发送多通知

Android本地服务绑定(bind)和后台线程