android从SD卡读取图像 [英] android reading an image from SD Card

查看:57
本文介绍了android从SD卡读取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to read an image from my SD Card and I'm not sure if I'm doing it right or not. Need some help please

这是我的阅读代码:

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

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

This will ensure you find the correct directory!

这篇关于android从SD卡读取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆